-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.babel.js
77 lines (72 loc) · 1.65 KB
/
webpack.config.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import webpack from 'webpack';
import path from 'path';
import WebpackStatsPlugin from 'stats-webpack-plugin';
const env = process.env.NODE_ENV;
const generateStats = process.env.WEBPACK_STATS || false;
const libraryName = `react-injectables`;
const outputFileName = `${libraryName}.js`;
const reactExternal = {
root: `React`,
commonjs2: `react`,
commonjs: `react`,
amd: `react`
};
const config = {
entry: path.resolve(__dirname, `./src/index.js`),
externals: {
react: reactExternal
},
module: {
preLoaders: [
{ test: /\.js$/, loaders: [`eslint-loader`], exclude: /node_modules/ }
],
loaders: [
{
test: /\.js$/,
loaders: [`babel-loader`],
include: [path.resolve(__dirname, `./src`)],
exclude: /node_modules/
}
]
},
output: {
path: path.resolve(__dirname, `./lib`),
filename: outputFileName,
library: libraryName,
libraryTarget: `umd`,
umdNamedDefine: true
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env)
})
],
eslint: {
failOnError: true,
failOnWarning: true
}
};
if (env === `production`) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
warnings: false
}
})
);
}
if (generateStats) {
config.plugins.push(
new WebpackStatsPlugin(`stats.json`, {
chunkModules: true,
exclude: [/node_modules[\\\/]react/]
})
);
}
export default config;