-
Notifications
You must be signed in to change notification settings - Fork 26
/
webpack.config.js
106 lines (92 loc) · 2.54 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
'use strict';
let commonConfig = require('./webpack.common.config');
let webpack = require('webpack');
let path = require('path');
let merge = require('webpack-merge');
let CopyWebpackPlugin = require('copy-webpack-plugin');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
let npmLifecycleEvent = process.env.npm_lifecycle_event || '';
let environment = process.env.NODE_ENV || '';
let contextReplacementPlugin = new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/angular(\\|\/)core(\\|\/)@angular/,
path.join(process.cwd(), 'src')
);
let commonPlugins = [
new webpack.optimize.CommonsChunkPlugin({ name: ['main', 'vendor'], minChunks: Infinity }),
new ExtractTextPlugin('style.bundle.css'),
new webpack.ProgressPlugin(),
contextReplacementPlugin
];
let cssLoader = {
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader'
})
};
let entry = {
'main': './app/main.js',
'vendor': './app/vendor.js',
'style': './app/style.js',
};
let output = {
path: path.resolve(process.cwd(), 'dist'),
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
};
if (npmLifecycleEvent == 'build' || environment == 'production') {
module.exports = merge.smart(commonConfig, {
entry: entry,
output: output,
plugins: commonPlugins.concat([
new webpack.LoaderOptionsPlugin({
debug: false,
minimize: true
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
mangle: { screw_ie8 : true },
compress: {
screw_ie8: true,
warnings: false
}
}),
new CopyWebpackPlugin([
{ from: 'index.html' },
{ from: 'favicon.ico' }
])
]),
module: {
rules: [cssLoader]
},
devtool: 'source-map'
});
} else if (npmLifecycleEvent.indexOf('test') !== -1 || environment == 'test') {
module.exports = merge.smart(commonConfig, {
devtool: 'inline-source-map',
plugins: [contextReplacementPlugin, new webpack.ProgressPlugin()]
});
} else {
module.exports = merge.smart(commonConfig, {
entry: entry,
output: output,
plugins: commonPlugins,
module: {
rules: [cssLoader]
},
devServer: {
contentBase: './src',
port: 3000,
inline: true,
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 300,
poll: 500
},
stats: 'errors-only'
},
devtool: 'cheap-module-source-map'
});
}