webpack-config icon indicating copy to clipboard operation
webpack-config copied to clipboard

Using require instead of import?

Open burzum opened this issue 7 years ago • 1 comments

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?

burzum avatar Jan 22 '18 13:01 burzum

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.

ethyde avatar May 26 '18 08:05 ethyde