-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
101 lines (92 loc) · 2.21 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
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const isProduction = process.env.NODE_ENV === 'production'
const outputPath = process.env.GITHUB === 'true' ? path.resolve(__dirname, '..', 'tuqire.github.io', 'kabaa-project') : path.resolve(__dirname, 'dest')
const plugins = [
new webpack.optimize.ModuleConcatenationPlugin(),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'html', 'index.html'),
minify: isProduction && {
html5: true,
collapseWhitespace: true,
caseSensitive: true,
removeComments: true
}
}),
new CopyWebpackPlugin([
{ from: 'src/images', to: 'images' }
]),
new webpack.ProvidePlugin({
THREE: 'three'
}),
new CleanWebpackPlugin()
]
if (process.env.NODE_ENV === 'production') {
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
)
plugins.push(
new webpack.HashedModuleIdsPlugin()
)
}
module.exports = env => ({
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'none' : 'eval-source-map',
entry: {
main: path.resolve(__dirname, 'src', 'js', 'main.js')
},
output: {
filename: 'js/[name].[hash].js',
path: outputPath
},
module: {
rules: [
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.(js)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
optimization: {
runtimeChunk: 'single',
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: !isProduction
})
],
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
},
resolve: {
extensions: ['.js', '.json']
},
plugins,
devServer: {
contentBase: path.join(__dirname, 'dest'),
port: 8080
}
})