-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
112 lines (110 loc) · 2.51 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
/* eslint-disable */
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
module.exports = (env, args) => {
const mode = args.mode || "development";
const isDevelopment = mode === 'development';
console.log('Webpack mode: ' + mode)
return {
mode: mode,
entry: {
main: './index.js'
},
watch: isDevelopment,
output: {
filename: isDevelopment ? '[name].bundle.js' : '[name]_[hash].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
resolve: {
modules: [
'node_modules',
],
extensions: ['.js', '.jsx', '.css'],
alias: {
'@modules': path.resolve(__dirname, 'node_modules'),
'three': path.resolve(__dirname, 'node_modules', 'three', 'build', 'three.js'),
'@images': path.resolve(__dirname, 'image'),
'@shaders': path.resolve(__dirname, 'node_modules', 'three', 'examples', 'js', 'shaders'),
'@postprocessing': path.resolve(__dirname, 'node_modules', 'three', 'examples', 'js', 'postprocessing')
},
},
devtool: 'eval',
target: 'web',
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true,
}),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
DEBUG: true,
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'dist', 'index.html'),
template: path.resolve(__dirname, 'index.html'),
inject: true,
chunks: ['main', 'commons'],
chunksSortMode: 'manual',
}),
new webpack.ProvidePlugin({
THREE: 'three'
})
],
module: {
rules: [{
test: /\.jsx?$/,
include: [__dirname],
exclude: [/node_modules/, /modernizr-custom\.js/],
use: [{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
}
}, {
loader: 'eslint-loader',
}]
},
{
test: /\.(jpg|png|svg|gif|mp4|webp)$/,
loader: 'file-loader',
options: {
outputPath: './image',
},
}
],
},
devServer: {
contentBase: path.join(__dirname),
compress: true,
port: 9000,
host: 'localhost',
hot: true,
},
optimization: {
minimizer: isDevelopment ? [
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
output: {
comments: false,
beautify: false
},
}
})
] : [],
splitChunks: {
maxAsyncRequests: 5,
cacheGroups: {
commons: {
name: 'commons',
chunks: 'all',
minChunks: 2,
minSize: 0
}
}
}
}
}
}