-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
97 lines (92 loc) · 2.12 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
const path = require('path');
const pathOutput = path.resolve(__dirname, 'dist');
const pathNodeModules = path.resolve(__dirname, 'node_modules');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
// const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
// .BundleAnalyzerPlugin;
const TerserPlugin = require('terser-webpack-plugin');
const env = process.env.NODE_ENV;
const isProd = env === 'production';
console.log('Environment isProd :', isProd);
const entry = isProd ? { app:'./src/js/app.js' }
: { app:'./src/js/app.js', debug:'./src/js/debug/debug.js' };
const output = isProd ? {
filename:'assets/js/app.js',
path: pathOutput
} : {
filename:'assets/js/[name].js',
path: pathOutput
};
const devtool = isProd ? 'source-map' : 'inline-source-map';
module.exports = {
entry,
devtool,
output,
devServer: {
host:'0.0.0.0',
contentBase: './dist',
hot:true,
disableHostCheck:true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.hbs$/,
exclude: /node_modules/,
use: {
loader: 'handlebars-loader'
}
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: { minimize: true }
}
]
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.scss$/,
use: [
'style-loader', // creates style nodes from JS strings
'css-loader', // translates CSS into CommonJS
'sass-loader' // compiles Sass to CSS, using Node Sass by default
]
},
{
test: /\.(glsl|vert|frag)$/,
use: ['raw-loader', 'glslify-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
})
// new BundleAnalyzerPlugin()
],
optimization: {
minimizer: [new TerserPlugin({ parallel: true })]
},
resolve: {
alias: {
alfrid: path.resolve(__dirname, 'src/js/lib/alfrid/alfrid.js'),
libs:path.resolve(__dirname, 'src/js/libs'),
shaders:path.resolve(__dirname, 'src/shaders')
}
}
};