-
Notifications
You must be signed in to change notification settings - Fork 915
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
Preprocessing templates before sending them to vue-loader #542
Comments
#531 seems to be another use case for preprocessing. |
I'm developing a tool |
I have been trying to create a custom markdown-loader which would ideally rely on vue-loader, but had the same issues and wasn't able to solve it with vue-loader configuration. Why us vue-loader bypassing the content from webpack and accessing the files directly? |
Now supported in 10.1.0 / 8.6.0 |
works by using 10.1.0 or higher |
Background
Recently I'm experimenting with feature toggles (feature flags) within Vue.js. It is fairly easy to implement for JavaScript code with webpack's
DefinePlugin
andUglifyJSPlugin
, but when it comes to templates in.vue
files, it is a little bit tricky.What I have in mind is to preprocess the
.vue
files and remove some markup in the<template>
block before sending it tovue-loader
so that I can dictate what's included in the final build. As an example, say I have the following vue component:And I have my
AWESOME_FEATURE
feature toggle set tofalse
, I would like to preprocess the template and send the following code tovue-loader
:I have tried to chain my preprocessing loader before
vue-loader
like the following (in webpack config):However, this does not work. I then verified that my
vue-features-loader
does pass the correct content tovue-loader
, andvue-loader
indeed received the corrent content, but the final build code does not seem to be affected.When I looked at the source code of
vue-loader
, I found that what it does is just generating arequire
statement for each part of thevue
file and using aselector
module to read directly from thevue
file. So loaders sitting in between the source file andvue-loader
cannot really do their jobs as expected, because the generate require statement does not reference them.The Impact
This problem impacts all scenarios where any sort of preprocessing needs to be done on the
.vue
source files.Although we can use the
vue.loaders
config to swap out the default loaders entirely and replace them with custom loaders, but this is not trivial, and not necessary in most cases.Proposed Solutions
A possible solution to this problem would be to pass content selected with the
selector
module to those loaders falling in between the source file andvue-loader
.Another solution might be allowing users to specify extra loaders to preprocess each part of the
vue
file. (This is not to replace the default loaders via thevue.loaders
config, but to add in additional loaders to do preprocessing, and still pass the output to the default loaders)The text was updated successfully, but these errors were encountered: