So I want to do:
if (process.env.NODE_ENV === 'production') {
import StatsPlugin from 'webpack-stats-plugin';
}
But eslint says:
Parsing error: 'import' and 'export' may only appear at the top level
I'm using babel-eslint parser.
Does this imply I can't load modules conditionally?
Dynamic synchronous imports are not possible with ES2015 modules. It's only possible to import stuff dynamically with asynchronous imports via import()
.
Why don't you just import it and apply it conditionally?
import StatsPlugin from 'webpack-stats-plugin';
...
if (process.env.NODE_ENV === 'production') {
config.plugins.push(new Statsplugin())
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With