-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.babel.js
106 lines (94 loc) · 2.46 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CompressionPlugin from 'compression-webpack-plugin';
import alias from 'whs/tools/alias';
const isProduction = process.env.NODE_ENV === 'production';
const config = {
entry: {
app: './app/app.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules\/(?!whs)|bower_components)/,
loader: 'babel-loader',
query: {
plugins: [
'add-module-exports',
'transform-decorators-legacy',
'transform-class-properties',
'transform-object-rest-spread',
['transform-runtime', {helpers: false, polyfill: false, regenerator: true}]
]
}
},
{
test: /\.(glsl|frag|vert)$/, loader: 'raw-loader', exclude: /node_modules/
},
{
test: /\.(glsl|frag|vert)$/, loader: 'glslify-loader', exclude: /node_modules/
}
]
},
plugins: pluginsList(isProduction),
output: {
path: path.join(__dirname, './build/'),
filename: '[name].[chunkhash].js'
},
devServer: {
publicPath: '/',
stats: { chunks: true }
},
resolve: {
symlinks: false,
modules: [path.resolve('node_modules')]
}
};
function pluginsList(prod) {
const plugins = [
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor'],
chunks: ['app'],
minChunks: function (module) {
return isExternal(module)
}
}),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
filename: 'index.html',
title: 'whs boilerplate app',
template: 'index-template.html',
chunks: ['vendor', 'app']
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 1024,
minRatio: 0.8
})
];
if(prod) {
plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new webpack.optimize.UglifyJsPlugin())
}
return plugins;
}
function isExternal(module) {
const userRequest = module.userRequest
if (typeof userRequest !== 'string') {
return false
}
return userRequest.indexOf('bower_components') >= 0 ||
userRequest.indexOf('node_modules') >= 0 ||
userRequest.indexOf('libraries') >= 0
}
export {
config as default
};