-
Notifications
You must be signed in to change notification settings - Fork 39
/
webpack.config.js
120 lines (114 loc) · 3.57 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
var _ = require('lodash');
var chalk = require('chalk');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var OpenBrowserWebpackPlugin = require('open-browser-webpack-plugin');
var PARAMS_DEFAULT = {
entry: {
main: './src/main.js',
vendor: ['lodash', 'jquery', 'bootstrap', 'angular', 'angular-animate', 'angular-ui-bootstrap']
},
output: {
filename: '[name].[chunkhash].js',
sourceMapFilename: '[name].[chunkhash].map'
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
inject: 'body'
}),
new webpack.ProvidePlugin({
// https://github.com/angular/angular.js/blob/v1.5.9/src/Angular.js#L1821-L1823
// http://blog.johnnyreilly.com/2016/05/the-mysterious-case-of-webpack-angular-and-jquery.html
'window.jQuery': 'jquery',
'jQuery': 'jquery'
}),
new webpack.optimize.DedupePlugin()
],
devServer: {
port: 8081
}
};
var PARAMS_PER_TARGET = {
DEV: {
devtool: 'inline-source-map',
output: {
filename: '[name].js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.js'
}),
new OpenBrowserWebpackPlugin({
url: 'http://localhost:' + PARAMS_DEFAULT.devServer.port
})
]
},
BUILD: {
output: {
path: './build'
},
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(['build']),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.[chunkhash].js',
minChunks: Infinity
})
]
},
DIST: {
output: {
path: './dist',
// TODO remove hack-fix when gh-pages work again
publicPath: '/angular-js-es6-testing-example/'
},
plugins: [
new CleanWebpackPlugin(['dist']),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.[chunkhash].js',
minChunks: Infinity
}),
new webpack.optimize.UglifyJsPlugin({
mangle: false
})
]
}
};
var TARGET = process.env.NODE_ENV || 'BUILD';
var params = _.merge(PARAMS_DEFAULT, PARAMS_PER_TARGET[TARGET], _mergeArraysCustomizer);
_printBuildInfo(params);
module.exports = {
resolve: params.resolve,
entry: params.entry,
output: params.output,
module: {
loaders: [
{test: /\.js$/, loader: 'babel-loader', exclude: /(\.test.js$|node_modules)/},
{test: /\.css$/, loader: 'style-loader!css-loader'},
{test: /\.tpl.html/, loader: 'html-loader'},
{test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/, loader: 'url-loader?limit=50000'}
]
},
plugins: params.plugins,
devServer: params.devServer,
devtool: params.devtool
};
function _printBuildInfo(params) {
console.log('\nStarting ' + chalk.bold.green('"' + TARGET + '"') + ' build');
if (TARGET === 'DEV') {
console.log('Dev server: ' +
chalk.bold.yellow('http://localhost:' + params.devServer.port + '/webpack-dev-server/index.html') + '\n\n');
} else {
console.log('\n\n');
}
}
function _mergeArraysCustomizer(a, b) {
if (_.isArray(a)) {
return a.concat(b);
}
}