Skip to content

feat: Call custom block loaders with Component as argument #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2017

Conversation

hauptbenutzer
Copy link

I love the idea of single file vue components and of being able to add custom blocks such as <docs>. Although it is possible to pass arguments to the loader via attributes on the custom block tag, you cannot access the Component from inside the loader. I needed that functionality to achieve the following.

  1. Have a <docs> tag in the .vue file
  2. Have the contents of said tag inserted into the resulting Component as options._docs so that it would be accessible during runtime.

A very simple custom loader for this task could, for example, look like this:

module.exports = function (source, map) {
  this.callback(null, 'module.exports = function(Component) {Component.options._docs = ' +
    JSON.stringify(source) +
    '}', map)
}

So I changed the call of the customBlock to include Component, if the result of the require is a function. I'm not sure if this would break any existing workflows.

If you think this use case is worth considering I'd be happy to supply the corresponding unit tests and docs.

@yyx990803
Copy link
Member

Neat idea, mind adding a test case for this?

@hauptbenutzer hauptbenutzer force-pushed the feature/call_custom_blocks branch from 198ca2f to 3d7d91d Compare February 25, 2017 22:13
@hauptbenutzer
Copy link
Author

Sure thing! I've added some example docs as well.

@hauptbenutzer hauptbenutzer force-pushed the feature/call_custom_blocks branch from 3d7d91d to f97b929 Compare February 25, 2017 22:42
@kazupon kazupon requested a review from yyx990803 March 1, 2017 03:24
this.callback(null, 'module.exports = function(Component) {Component.options.__docs = ' +
JSON.stringify(source) +
'}', map)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky me here: I think we need a new line.

@hauptbenutzer hauptbenutzer force-pushed the feature/call_custom_blocks branch from fbda704 to a8a3aaf Compare March 10, 2017 08:57
@egoist
Copy link

egoist commented Mar 20, 2017

/cc @yyx990803

@yyx990803 yyx990803 merged commit 11cec30 into vuejs:master Mar 23, 2017
@yyx990803
Copy link
Member

@hauptbenutzer thanks for the PR and great docs example!

@anteriovieira anteriovieira mentioned this pull request Mar 24, 2017
kazupon added a commit to kazupon/vue-loader that referenced this pull request Mar 24, 2017
kazupon added a commit to kazupon/vue-loader that referenced this pull request Mar 24, 2017
kazupon added a commit that referenced this pull request Mar 24, 2017
* pick up from #664

* translate #664

* improve title

from review comment: #737 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants