Reputation: 177
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?
Upvotes: 8
Views: 5341
Reputation: 17805
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())
}
Upvotes: 5