Skip to content
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

Support for custom .vue blocks #31

Merged
merged 3 commits into from
Aug 10, 2018

Conversation

abrenneke
Copy link
Contributor

I've added support for custom <blocks> in .vue files.

It piggybacks on top of require-extension-hooks too, and prefixes the block names with vue-block-. So for example if you add a hook for vue-block-json, then you can parse a <json> block and do whatever you like with it.

The return value of the hook is appended to the compiled .vue file, so you can run anything you like in there.

What do you think?

Copy link
Owner

@jackmellis jackmellis left a comment

Choose a reason for hiding this comment

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

This is a really nice enhancement. Could you go through the requested changes and I'll hopefully get this merged and released soon

README.md Outdated
@@ -42,6 +42,25 @@ hooks('ts').push(function({content}){
/* transpile your script code here */
});
```

For custom blocks in `.vue` files, add other require hooks for the name of the blocks,
Copy link
Owner

Choose a reason for hiding this comment

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

Can you give this section its own header? I think it's a big-enough (and optional) feature that it deserves its own section

README.md Outdated
@@ -62,9 +81,9 @@ plugin.configure({ transpileTemplates: false });
```

### transpileTemplates
`true`
Copy link
Owner

Choose a reason for hiding this comment

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

Can you re-add the whitespace from these two lines as they're needed for line breakage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grr, my editor removed the end-of-line whitespace automatically. Never seen end-of-line whitespace actually matter before.

README.md Outdated

You can access the exported options object using (as vue-template-compiler does itself):
```javascript
((module.exports.default || module.exports).options || module.exports.default || module.exports)
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not overly keen on having this example in the docs as it's not pretty. Instead could you replace this whole paragraph with an explanation that the returned content will be appended to the file

README.md Outdated
hooks('vue').plugin('vue');
hooks('vue-block-json').push(({ content }) => {
// Strings returned here will be appended to the compiled .vue file. This should return JavaScript, in a string.
return '';
Copy link
Owner

Choose a reason for hiding this comment

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

Can you have this example show something more realistic than an empty string?

Something like export const jsonBlock = ${content}

Another option which might be good would be to export this string as a constant from the package for people to use. So your hook would look something like ${COMPONENT_EXPORT}.name = ${content}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea!

@jackmellis jackmellis self-assigned this Aug 9, 2018
@abrenneke
Copy link
Contributor Author

@jackmellis cleaned up the readme per your recommendations. Let me know if I went overboard for the example - it's a real-world use case, I've found that adding a mixin is the safest way to add functionality to a component.

COMPONENT_OPTIONS is attached to the plugin function to use now. I felt it was a more descriptive name of what you're modifying (the options object, not the Vue instance itself). If you like COMPONENT_EXPORT better I can change it.

@jackmellis jackmellis merged commit 1067424 into jackmellis:master Aug 10, 2018
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.

2 participants