`DefinePlugin` does not work if `loader` modifies the code
See original GitHub issuePre-determined plugin/loader order causes bugs in my application:
- I have a custom
babel
plugin which modifies code. - This causes
DefinePlugin
to fail because it seems to operate onbabel
output, not input, code. It thus cannot recognize what to replace in the code.
How can I tell DefinePlugin
to run before babel-loader
?
I don’t see any configuration option for that. Not sure, if that is an oversight, or if there is a way to fix this at all?
I setup a repository that illustrates the issue: https://github.com/Domiii/webpack-plugin-order-test
PS: I am not sure if this a bug or a feature request or something else.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
webpack.DefinePlugin - unable to get any substitution to work
My actual use case is far more complex, but the problem I am experiencing is demonstrated via the following minimal code and configuration....
Read more >Environment Variables - SurviveJS
Sometimes a part of your code should execute only during development. ... Webpack's DefinePlugin enables replacing free variables so that you can convert...
Read more >Adding a Custom webpack Config - Gatsby
When Gatsby creates its webpack config, this function will be called allowing you to modify the default webpack config using webpack-merge.
Read more >DefinePlugin | webpack
The DefinePlugin replaces variables in your code with other values or expressions at compile time. This can be useful for allowing different behavior ......
Read more >How to Customize Your Angular Build With Webpack
Webpack is not limited to simply bundling source files. ... Webpack module loaders are able to parse different file types.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexander-akait, thank you for your feedback!
I guess the string-replace-loader would be preferrable, seeing how it is a lot more widely used 😃
Answered. My recommendation - create simple loader and replace values using
RegExp
, as I said earlier, unfortunately this is not possible toDefinePlugin
before loaders (I’ll correct myself, this is theoretically possible if you only usestage 4
), but in your case you are usingbabel
so your code can be in any stage, even more you can use experimental syntax that may never be part of ECMA and here is the main problem, we can’t parse this syntax.Other solution - https://github.com/jean-smaug/babel-plugin-search-and-replace
Feel free to feedback