-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathwebpack.config.js
99 lines (82 loc) · 2.38 KB
/
webpack.config.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const packageConfig = require('./package.json');
const appEnv = process.env.NODE_ENV || 'development';
const appPath = path.join(__dirname, 'app');
const distPath = path.join(__dirname, 'dist');
const exclude = /node_modules/;
const config = {
devtool: '#inline-source-map',
// The base directory for resolving `entry` (must be absolute path)
context: appPath,
entry: {
app: 'app.js',
vendor: Object.keys(packageConfig.dependencies)
},
output: {
// The bundling output directory (must be absolute path)
path: distPath,
// Set proper base URL for serving resources
publicPath: '/',
// The output filename of the entry chunk, relative to `path`
// [name] - Will be set per each key name in `entry`
filename: 'bundle.[hash].js'
},
plugins: [
// Generate index.html with included script tags
new HtmlWebpackPlugin({
inject: 'body',
template: 'app/index.html'
}),
// Do not output to dist if there are errors
new webpack.NoErrorsPlugin(),
// Pass environment variable to frontend scipts
new webpack.DefinePlugin({
$_ENVIRONMENT: JSON.stringify(appEnv),
// We must envify CommonJS builds:
// https://github.com/reactjs/redux/issues/1029
'process.env.NODE_ENV': JSON.stringify(appEnv)
}),
// Generate the bundle file
new webpack.optimize.CommonsChunkPlugin(
/* chunkName: */ 'vendor',
/* filename: */ 'vendor.[hash].js'
)
],
// Enable loading modules relatively (without the ../../ prefix)
resolve: {
root: appPath
},
module: {
loaders: [
// Transpile ES6 and enable Hot Reload
{
test: /\.js$/,
loaders: [
'babel?cacheDirectory&plugins=babel-plugin-rewire'
],
exclude: exclude
}
]
},
externals: {
'cheerio': 'window',
},
// Settings for webpack-dev-server
// `--hot` and `--progress` must be set using CLI
devServer: {
contentBase: appPath,
colors: true,
noInfo: true,
inline: true,
historyApiFallback: true
},
postcss: [
autoprefixer({
browsers: ['last 2 versions']
})
]
};
module.exports = config;