-
Notifications
You must be signed in to change notification settings - Fork 16
/
webpack.prod.mjs
63 lines (61 loc) · 2.33 KB
/
webpack.prod.mjs
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
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import HTMLMinimizerPlugin from "html-minimizer-webpack-plugin";
import { LicenseWebpackPlugin } from "license-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
import packageJson from "./package.json" assert { type: "json" };
const ACCEPTABLE_LICENSES = ["MIT", "0BSD", "BSD-2-Clause", "BSD-3-Clause", "APACHE-2.0", "ISC", "Unlicense"];
export default function () {
return {
mode: "production",
plugins: [
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
}),
new LicenseWebpackPlugin({
outputFilename: "third-party-licenses.txt",
unacceptableLicenseTest: (licenseIdentifier) => {
const licenses = licenseIdentifier.replace(/[()]/g, "").split(" OR ");
return licenses.every((licenseName) => {
return !ACCEPTABLE_LICENSES.map((name) => name.toLowerCase()).includes(
licenseName.toLowerCase()
);
});
},
perChunkOutput: false,
skipChildCompilers: true,
excludedPackageTest: (packageName) => {
return packageName === packageJson.name;
},
}),
],
module: {
rules: [
{
test: /\.(s?)css$/,
use: [MiniCssExtractPlugin.loader, "css-loader", "postcss-loader", "sass-loader"],
sideEffects: true,
},
],
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
preamble: "/* See third-party-licenses.txt for licenses of any bundled software. */",
},
},
}),
new CssMinimizerPlugin(),
new HTMLMinimizerPlugin(),
],
splitChunks: {
chunks: "all",
},
},
devtool: false,
};
}