This repository was archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
150 lines (142 loc) · 3.69 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
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
//import path from 'path';
const path = require('path')
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CompressionPlugin from 'compression-webpack-plugin';
const isProduction = process.env.NODE_ENV === 'production';
const srcPath = path.resolve(__dirname, 'src');
const buildPath = path.resolve(__dirname, 'dist');
const config = {
context: srcPath,
entry: {
mine: './index.js',
boo: './scream/boo.js'
},
output: {
path: buildPath,
filename: '[name].bundle.js' // todo: on production: [name].[chunkhash]
},
devServer: {
hot: true,
inline: true,
contentBase: './src/',
host: '0.0.0.0',
publicPath: '/',
stats: {
assets: false,
colors: true,
chunkModules: false,
version: false,
hash: false,
timings: false,
chunks: true,
chunkModules: false,
modules: false
}
},
devtool: isProduction ? 'cheap-module-source-map' : 'cheap-module-eval-source-map',
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|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)$/,
exclude: /(node_modules|bower_components)/,
loader: 'raw-loader',
},
{
test: /\.(glsl|frag|vert)$/,
exclude: /(node_modules|bower_components)/,
loader: 'glslify-loader',
},
{
test: /\.html$/,
exclude: /(node_modules|bower_components)/,
loader: 'file-loader?name=[name].[ext]'
}
]
},
plugins: pluginsList(isProduction),
resolve: {
symlinks: false,
modules: [path.resolve('node_modules')]
}
};
function pluginsList(prod) {
const plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor'],
chunks: ['app'],
minChunks: function (module) {
return isExternal(module)
}
}),
new webpack.NamedModulesPlugin(),
// multiple entrypoints
// /
new HtmlWebpackPlugin({
title: "React+Redux & threejs",
filename: 'index.html',
template: path.resolve(srcPath, 'index.ejs'),
hash: true,
chunks: ['mine']
}),
// /boo
new HtmlWebpackPlugin({
title: "Booo!",
inject: 'head',
filename: 'boo/index.html',
template: path.resolve(srcPath, 'index.ejs'),
hash: true,
chunks: ['boo']
}),
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()
)
} else {
plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
)
}
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
};