-
Notifications
You must be signed in to change notification settings - Fork 916
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
[Question] Any loader hook provided before compile? #2039
Comments
Interestingly, I had the same need last week and I wasn't able to do much, as you said yourself, the So what I did was the opposite, I intercepted the source before passing it to Vue. So, in your webpack ruleset you might have something like this, right:
What I did was add another test for vue below it (webpack rule order go from last to first) and change the source before it goes to vue-loader, by running "my loader". Webpack requires loaders to have external files, so to avoid having to make my own, having to config aliases, etc etc, I instead am using So an example:
The caveat is that I don't have access to pretty parsed arrays like sfc's parse gives, split into style, script, template and having attributes list. So I had to work with RegExp directly on the string, which is not the best and very error prone if not tested properly, but is what I could come with as vue-loader has no pre-parse hook. Let me know if you find anything better than this lol. |
Hi @RaphaelDDL. Thanks for the reply. I am actually doing the same (as running a custom loader before vue-loader), yet I am still using the compiler-sfc to get the AST because I have the same exact reason as you, which is not to mess with regexp cause it's too much hassle and error-prone. I dont have any better/worse solution but I am now looking at migrating from webpack to vite. Hope can get some easy way out. Finger crossed. |
Hi, I am new to tap into the world of loader (webpack), may i know if the latest vue-loader have any lifecycle hooks (like preTransformNode previously) that I can tap into before the AST tree is being compiled? I need to manipulate some nodes for my usage.
I have quickly browser the source code but cant seems to find any. So I created a loader to run before vue-loader myself to make use of compileTemplte from @vue/compilet-sfc, but I is there any way I can transform it back to string template to pass to vue-loader?
Any guidance would be greatly appreciated. :)
The text was updated successfully, but these errors were encountered: