-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (107 loc) · 2.59 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Core imports.
const path = require('path');
const merge = require('webpack-merge');
const webpack = require('webpack');
// Constants.
const PATHS = {
app: path.join(__dirname, 'app'),
build: path.join(__dirname, 'build'),
};
// Plugin imports.
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// Plugin definitions.
// Reduce letiable name size.
const occurrenceOrderPlugin = new webpack.optimize.OccurrenceOrderPlugin();
// Set environment as production to reduce React library size.
const definePlugin = new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
});
// Clear build/ directory before each build.
const cleanWebpackPlugin = new CleanWebpackPlugin([PATHS.build], {
root: process.cwd(),
verbose: true,
});
// let appConfig = require('./config/default.json');
// Webpack configuration.
let config = {};
// Common configuration.
const common = {
entry: path.join(PATHS.app, 'index.jsx'),
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['es2015', 'react', 'stage-1'],
},
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css-loader!postcss-loader'),
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('css-loader!postcss-loader!sass-loader?precision=8'),
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
cleanWebpackPlugin,
new ExtractTextPlugin({
filename: 'style.[hash].css',
allChunks: true,
}),
new HtmlWebpackPlugin({
template: 'index.html',
xhtml: true,
}),
],
// externals: {
// config: JSON.stringify(appConfig),
// },
};
switch (process.env.npm_lifecycle_event) {
case 'build':
config = merge(
common,
{
output: {
path: PATHS.build,
filename: 'bundle.[hash].js',
publicPath: '/',
},
devtool: 'source-map',
plugins: [
definePlugin,
occurrenceOrderPlugin,
],
}
);
break;
case 'start':
default:
config = merge(
common,
{
devtool: 'eval-source-map',
output: {
path: PATHS.build,
filename: 'bundle.[hash].js',
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
},
}
);
break;
}
module.exports = config;