-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
146 lines (122 loc) · 3.28 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
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const config = require('./build-config');
/**
* Returns the Output file config based on
* the run-time environment
*
* @return {Object} Webpack's config for `output`
*/
function getOutputFilesConfig() {
let filename = '[name].js';
if (config.ENV === 'production') {
filename = '[name].[hash].js';
}
return {
filename: filename,
path: config.path.dist + '/bundles',
publicPath: '/bundles'
};
}
/**
* Returns the set of webpack loaders config based
* on the run-time environment
*
* @return {Array} Webpack's config for `modules.loaders`
*/
function getLoaders() {
return [
{
test: /\.js$/,
exclude: /node_modules/,
loaders: ['babel-loader']
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader']
})
},
{
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
loader: 'url-loader',
options: {
limit: 10000,
name: '/img/[name].[hash:8].[ext]'
}
}
];
}
/**
* Returns the set of webpack plugins based on
* the run-time environment
*
* @return {Array} Webpack's config for `plugins`
*/
function getPlugins() {
let cssFilename = '[name]';
if (config.ENV === 'production') {
cssFilename = '[name].[contenthash]';
}
const plugins = [
new ExtractTextPlugin({
filename: cssFilename + '.css'
}),
new HtmlWebpackPlugin({
filename: config.path.dist + '/index.html',
template: config.path.src + '/index.html',
inject: false
}),
new webpack.NamedModulesPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(config.ENV)
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
];
if (config.ENV !== 'development') {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true,
warnings: false
},
output: {
comments: false
},
sourceMap: true
})
);
}
return plugins;
}
console.log('Running Webpack in ' + config.ENV.toUpperCase() + ' mode \n');
module.exports = {
devtool: 'source-map',
entry: {
app: [
config.path.src + '/js/app.js'
]
},
output: getOutputFilesConfig(),
module: {
loaders: getLoaders()
},
plugins: getPlugins(),
watch: config.isWatchEnabled,
performance: {
hints: false
}
};