-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
95 lines (89 loc) · 2.3 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
/* eslint-env node, es6 */
/* eslint-disable @typescript-eslint/no-var-requires */
const { merge } = require('webpack-merge');
const path = require('path');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const TerserPlugin = require('terser-webpack-plugin');
// Shared configuration.
const commonConfig = {
context: path.resolve(__dirname, './src'),
entry: {
main: ['./js/main.ts', './scss/main.scss'],
ckeditor: './scss/ckeditor.scss',
print: './scss/print.scss',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'js/[name].js',
},
externals: {
jquery: 'jQuery',
},
module: {
rules: [
{
test: /\.(js|ts)$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.(ttf|eot|woff|woff2|svg)$/,
exclude: /graphics/,
type: 'asset/resource',
generator: {
filename: 'fonts/[hash][ext][query]',
publicPath: '../',
},
},
{
test: /\.(jpg|png|svg)$/,
exclude: /fonts/,
type: 'asset/resource',
generator: {
filename: 'graphics/[hash][ext][query]',
publicPath: '../',
},
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[name].css',
experimentalUseImportModule: false,
}),
new RemoveEmptyScriptsPlugin(),
],
};
// Development configuration.
const developmentConfig = {
mode: 'development',
devtool: 'cheap-module-source-map',
watch: true,
};
// Production configuration.
const productionConfig = {
mode: 'production',
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
};
// Export config based on the current environment.
if (process.env.NODE_ENV === 'production') {
module.exports = merge(commonConfig, productionConfig);
} else {
module.exports = merge(commonConfig, developmentConfig);
}