-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·163 lines (155 loc) · 4.16 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Created by pgotthardt on 14/01/16.
*/
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
.BundleAnalyzerPlugin;
/**
* Setting environmen, Please see scripts in package.json
*/
var isProduction = process.env.NODE_ENV === 'production';
/**
* Loaders
*/
var loaders = [
/**
* Babel Loader
* Reference: https://github.com/babel/babel-loader
*/
{
loader: 'babel',
test: /\.js$/,
include: [path.resolve(__dirname, 'src', 'js')],
query: {
plugins: [
'transform-runtime'
],
presets: ['es2015']
}
},
/**
* Find and replace loader for isEnabled('filter')
* Reference: visit loader directory in project
*/
{
test: /\.js$/,
loader: path.resolve('loader/findreplace'),
query: [{
find: "isEnabled\\('filter'\\)",
replace: 'true'
}]
}
];
var plugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
/**
* Webpack HTML Webpack Plugin
* Reference: https://github.com/jantimon/html-webpack-plugin
*/
new HtmlWebpackPlugin({
template: __dirname + '/index.html',
filename: 'index.html',
inject: true
}),
/**
* Webpack Define Plugin
* Reference: https://webpack.js.org/plugins/define-plugin/
*/
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(
process.env.NODE_ENV || 'development'
)
}
}),
/**
* Webpack bundle analyser plugin
* Reference: https://github.com/webpack-contrib/webpack-bundle-analyzer
*/
new BundleAnalyzerPlugin({
analyzerMode: 'server',
// Host that will be used in `server` mode to start HTTP server.
analyzerHost: '127.0.0.1',
// Port that will be used in `server` mode to start HTTP server.
analyzerPort: 8888
})
];
/**
* Extract text webpack plugin only for production.
* Reference: https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md
*/
var cssProduction = {
test: /\.(s)?css$/,
loader: ExtractTextPlugin.extract(['css-loader', 'sass-loader']),
include: [path.resolve(__dirname, 'src', 'css')],
}
/**
* SCSS/CSS loader for development mode.
*/
var cssDevelopment = {
test: /\.(s)?css$/,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
include: [path.resolve(__dirname, 'src', 'css')],
}
// Pusing all loader according to environment.
loaders.push(isProduction ? cssProduction : cssDevelopment);
/**
* Extract text plugin - Production only
*/
if (isProduction) {
plugins.push(new ExtractTextPlugin('style.css'));
}
/**
* UglifyJS Plugin - Production only
*/
if (isProduction) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
);
}
module.exports = {
entry: {
main: ['babel-polyfill', path.normalize(__dirname + '/src/js/main')]
},
devtool: 'cheap-module-source-map',
output: {
filename: '[name].js',
path: path.join(__dirname, 'dist')
},
module: {
loaders: loaders
},
plugins: plugins,
devServer: {
contentBase: path.join(__dirname, './'),
compress: true
},
/**
* Make source map only in dev mode.
*/
devtool: !isProduction ? 'source-map' : false
/*
* Removed due to https://github.com/webpack/webpack/issues/1513
* resolveLoader: {
* alias: {
* 'isenabled': path.join(__dirname, 'loader', 'isenabled.js')
* }
* }
*/
};