-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathwebpack.config.js
More file actions
76 lines (75 loc) · 2.02 KB
/
webpack.config.js
File metadata and controls
76 lines (75 loc) · 2.02 KB
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
const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { RunInPuppeteerPlugin } = require("wsi-test-helper");
const expect = require("expect");
const fs = require("fs");
const path = require("path");
module.exports = {
mode: "none",
entry: {
index: "./index.js",
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[name].css",
}),
new SubresourceIntegrityPlugin({
hashFuncNames: ["sha256", "sha384"],
enabled: true,
}),
new HtmlWebpackPlugin(),
new RunInPuppeteerPlugin(),
{
apply: (compiler) => {
compiler.hooks.done.tap("wsi-test", (stats) => {
expect(stats.compilation.warnings).toEqual([]);
expect(stats.compilation.errors).toEqual([]);
const cssIntegrity = stats
.toJson()
.assets.find((asset) => asset.name === "style.css").integrity;
const source = fs.readFileSync(
path.join(__dirname, "./dist/runtime.js"),
"utf-8"
);
const sriManifest = JSON.parse(
source.match(/__webpack_require__.sriHashes = ({.+});/)?.[1] || "{}"
);
expect(sriManifest["style_css/mini-extract"]).toEqual(cssIntegrity);
});
},
},
],
output: {
crossOriginLoading: "anonymous",
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
modules: {
auto: true,
},
importLoaders: 1,
},
},
],
},
],
},
optimization: {
chunkIds: "named",
runtimeChunk: {
name: "runtime",
},
},
};