webpack-config
webpack-config copied to clipboard
Using require instead of import?
All the examples show the usage of import
but I can't manage to get the damn config files to go through babel or whatever is necessary and already wasted hours on this.
So how do I do the same using require()
or what do I need to do to get webpack3 to work with babel and import
?
Hello,
I have found 2 solutions :
With require
// in webpack.config.js
const { Config, environment } = require('webpack-config')
environment.setAll({
env: () => process.env.NODE_ENV
})
module.exports = new Config().extend('config/webpack.[env].config.js')
for webpack.base.config
// webpack.base.config.js
const webpack = require('webpack')
const { Config } = require('webpack-config')
module.exports = new Config().merge({
context: path.resolve(__dirname, '../app'),
// base config
})
and for other webpack.[env].config
const { Config } = require('webpack-config')
module.exports = new Config().extend('config/webpack.base.config.js').merge({
// config
})
Or you can rename webpack.config.js
to webpack.config.babel.js
and add babel-register. But babel-register add some
Webpack use interpret to make this work.