Closed NE-SmallTown closed 4 years ago
@sodatea Would you mind take a look?
Is there anything I could help to move this forward?
What's the usage of it?
If it's for the purpose mentioned in this issue https://github.com/vuejs/vue-loader/issues/1603 Then as Evan said, it's out of the scope of this package.
IMO this is not related to vuejs/vue-loader#1603 (because my attention here is not to parse script/style), I want to do something like below:
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
}
],
exclude: path.resolve(__dirname, 'xxx')
},
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
compilerOptions: {
modules: [
{
transformNode: el => {
...
return el;
},
},
],
},
},
}
],
include: path.resolve(__dirname, 'xxx'),
}
but you will find that it doesn't work, the compilerOptions
will be adopted for all vue files, so I think the way of this PR is the only (correct)way I could imagine to do this
Do you have a reproduction repository?
Could possibly be a bug in vue-loader
Here is the repro: https://github.com/NE-SmallTown/vue-compiler-options-bug-repro , sorry have no time to dig into the src code of vue-loder
It's a bug in vue-loader/lib/plugin
that it only checks for the first rule that matches .vue
files.
Next time please raise an issue before creating a PR because it could be an XY Problem (See also https://coolshell.cn/articles/10804.html for the Chinese version)
Thanks for your response, but from my personal perspective, this is not a XY problem because this PR is not trying to fix the bug(but yes, you can "fix" it with this PR), its purpose is to make the compilerOptions.modules
more flexible(the bug fix is just one part of the "flexible"), the misunderstanding of your focus move to XY problem may because I delete the beginning word 'if' in 'I want to do something like below:' during one edit
What else use cases could this feature resolve?
BTW in your implementation, the filename
option would be passed to the vue-template-compiler
instance, methods in modules
still could not get it.
What else use cases could this feature resolve?
For example, I want to generate some Identities based on the filename, BTW, there is no secure/privacy problem because compilerOptions
is Opt-in.
BTW in your implementation, the filename option would be passed to the vue-template-compiler instance, methods in modules still could not get it.
I think it could because I test it locally and after that I create this PR, you can check it from this line, the options
passed to preTransforms
is from the parse
function which received options
from this PR.
I think it could because I test it locally and after that I create this PR, you can check it from this line, the
options
passed topreTransforms
is from theparse
function which receivedoptions
from this PR.
Thanks for the note. It is supported, though not well documented.
I'm still struggling to find good use cases for this option. Need some more time to think about it.
@znck any thoughts?
Hey @NE-SmallTown, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚
Thanks.
Need to address the new filename field in vue-template-compiler type definitions;
Did you mean the TemplateCompileOptions
type definition? I find that the definitions have been existed in the both RADME.md
and compilerTemplate.ts
in the init commit of component-compiler-utils
Need to provide similar functionalities in the new compiler-sfc package in Vue 3.
Don't know this before, seems it's a "TODO" package, at least for compilerTemplate.ts
, so I think currently maybe it's not a follow-up of this PR?
Another work I can imagine is to update the dependency version in vue-loader
Yeah, not a follow up, just backlog.
Ideally, the type definition in the vue-template-compiler
package should be updated and exported and we just import that in this package to replace the definition here
Pass the filename option to compiler, so the compiler can get and pass it down in some cases like
transformNode/preTransformNode/postTransformNode