-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
71 lines (61 loc) · 2.07 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
// For info about this file refer to webpack and webpack-hot-middleware documentation
// Rather than having hard coded webpack.config.js for each environment, this
// file generates a webpack config for the environment passed to the getConfig method.
var webpack = require('webpack');
var path = require('path');
var getPlugins = function(env) {
var plugins = [new webpack.optimize.OccurenceOrderPlugin()];
switch(env) {
case 'production':
plugins.push(new webpack.optimize.DedupePlugin());
plugins.push(new webpack.optimize.UglifyJsPlugin({minimize: true, sourceMap: true}));
break;
case 'development':
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.NoErrorsPlugin());
break;
}
return plugins;
};
var getLoaders = function(env) {
var sourcemaps = env == 'produciton' ? '' : '?sourceMap';
var loaders = [
{
test: /\.js$/,
include: path.join(__dirname, 'src'),
loaders: ['babel', 'eslint']
},
{
test: /(\.css|\.scss)$/,
include: path.join(__dirname, 'src'),
loaders: ['style', 'css'+sourcemaps, 'sass'+sourcemaps]
}
];
return loaders;
};
var getEntry = function(env) {
var entry = [];
if (env == 'development') { //only want hot reloading when in dev.
entry.push('webpack-hot-middleware/client');
}
entry.push('./src/index');
return entry;
};
module.exports = function getConfig(env) {
return {
debug: true,
devtool: env === 'production' ? false : 'eval-cheap-module-source-map', //more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
noInfo: true, //set to false to see a list of every file being bundled.
entry: getEntry(env),
target: env == 'test' ? 'node' : 'web', //necessary per https://webpack.github.io/docs/testing.html#compile-and-test
output: {
path: __dirname + '/dist/js',
publicPath: '/js/',
filename: 'bundle.js'
},
plugins: getPlugins(env),
module: {
loaders: getLoaders(env)
}
};
};