-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.config.js
101 lines (99 loc) · 3.58 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
/**
* ██ ██ ██ ███ ███ ██████
* ██ ██ ██ ████ ████ ██ ██
* ██ ██ ██ ██ ████ ██ ██████
* ██ ██ ██ ██ ██ ██ ██ ██
* █████ ██████ ██ ██ ██
*
* @author Dale Davies <[email protected]>
* @copyright Copyright (c) 2022, Dale Davies
* @license MIT
*/
const path = require('path');
const Terser = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const VersionFilePlugin = require('webpack-version-file');
module.exports = {
mode: 'production',
entry: {
index: './jumpapp/assets/js/src/index.js',
styles: './jumpapp/assets/css/src/index.scss',
},
output: {
filename: '[name].[contenthash].min.js',
path: path.resolve(__dirname, './jumpapp/assets/js/'),
},
module: {
rules: [
{
test: /\.(s(a|c)ss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader
},
{
loader: 'css-loader',
options: {
url: false // Stop webpack emitting image/font from URLs found in CSS.
}
},
'sass-loader',
],
},
{
test: /\.jump-version/,
type: 'asset/source',
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, './jumpapp/templates/partials/cssbundle.mustache'),
template: path.resolve(__dirname, './jumpapp/templates/partials/src/cssbundle.src.mustache'),
inject: false,
minify: false, // Required to prevent addition of closing tags like body and html.
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, './jumpapp/templates/partials/jsbundle.mustache'),
template: path.resolve(__dirname, './jumpapp/templates/partials/src/jsbundle.src.mustache'),
inject: false,
minify: false,
}),
new MiniCssExtractPlugin({filename: '../css/[name].[contenthash].min.css'}),
new RemoveEmptyScriptsPlugin(),
new CleanWebpackPlugin({
dry: false,
verbose: true,
cleanStaleWebpackAssets: true,
cleanOnceBeforeBuildPatterns: [
'index.*.min.js',
path.resolve(__dirname, './jumpapp/assets/css/styles.*.min.css')
],
dangerouslyAllowCleanPatternsOutsideProject: true,
}),
new VersionFilePlugin({
data: {
date: Math.floor(Date.now() / 1000),
},
output: './jumpapp/.jump-version',
templateString: 'v<%= version %> (<%= date %>)',
}),
],
optimization: {
minimizer: [
new Terser({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
new CssMinimizerPlugin(),
],
},
};