webpack.config.js tips
new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true, // foo.bar or foo["bar"]) doesn't have any side effects.
unsafe: true, // several transforms exp.toString() → "" + exp, Array(1, 2, 3) → [ 1, 2, 3 ], new Object/RegExp/Function/Error/Array (...) → we discard the new, ..
unsafe_comps: true, // unsafe comparaison <= to > etc.
screw_ie8: true, // special identifier not between quote (as ie8 needs) 'class' => class
warnings: false
}
})
resolve: {
extensions: ['', '.js'],
// the default is : ["", ".webpack.js", ".web.js", ".js"]
// '' : is needed when require('toto.js') (at least)
// '.js' : is needed when require('./src') (to find index.js)
alias: {
'react-line': path.resolve('src', 'index.js') // replace require('react-line') per require('./src./index.js')
'react-test': 'react' // 'react' instead of 'react-test'
// require('react-test/toto.js') ==> require('react/toto.js')
}
}
plugins: [
new webpack.NormalModuleReplacementPlugin(/\.css$/, 'node-noop'),
...
]
loaders: [{
test: /\.js$/,
loaders: ['babel-loader'],
//exclude: /node_modules/, // don't exclude, include instead !
include: [
path.resolve(__dirname, 'src'), // .resolve() give a absolute path
path.resolve(__dirname, 'node_modules', 'moduleName') // include that if the module is written in ES6 (to babelize it too)
// you need if you have this error for instance:
// Module parse failed: ...\index.js Line 1: Unexpected reserved word
// You may need an appropriate loader to handle this file type.
// | import React from 'react';
]
}]