-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
151 lines (137 loc) · 3.85 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const HtmlWebpackChangeAssetsExtensionPlugin = require("html-webpack-change-assets-extension-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const zlib = require("zlib");
const execSync = require("child_process").execSync;
const gitCommand = "git rev-parse HEAD";
const getGitHash = () => execSync(gitCommand).toString().trim();
module.exports = (env, argv) => {
const isProduction = argv.mode === "production";
return {
entry: {
index: "./src/index.ts",
playground: "./src/playground.ts",
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
clean: true,
},
resolve: {
extensions: [".ts", ".js", ".json", ".css", ".ttf"],
},
plugins: [
new HtmlWebpackPlugin({
title: "Yarn Spinner for JS",
template: "src/index.html",
jsExtension: ".br",
gitHash: getGitHash().substring(0, 8),
urlBase: process.env["BASE_URL"] || "",
}),
new HtmlWebpackPlugin({
title: "Yarn Spinner for JS",
template: "src/embed.html",
filename: "embed.html",
jsExtension: ".br",
gitHash: getGitHash().substring(0, 8),
urlBase: process.env["BASE_URL"] || "",
}),
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new MonacoWebpackPlugin({
languages: ["markdown"],
// filename: isProduction ? "[name].worker.js" : undefined,
}),
new CopyWebpackPlugin({
patterns: [{ from: "src/staticwebapp.config.json" }],
}),
...(isProduction
? [
new CompressionWebpackPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
// Don't compress *.worker.js, because Monaco doesn't know
// to look for .worker.js.br and isn't expecting it to be
// compressed
exclude: /\.worker\.js/,
threshold: 0,
minRatio: Infinity,
// If DELETE_ORIGINAL_ASSETS is 1, keep only the output and
// delete the input files
deleteOriginalAssets:
process.env["DELETE_ORIGINAL_ASSETS"] || 0 ? true : false,
}),
new HtmlWebpackChangeAssetsExtensionPlugin(),
]
: []),
],
devServer: {
static: "./dist",
watchFiles: [
"src/**/*.html",
"src/img/**/*",
"src/**/*.yarn",
"bin/**",
"scss/**/*.scss",
],
},
...(isProduction
? {
devtool: "source-map",
}
: {
devtool: "inline-source-map",
}),
mode: "development",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
// "postcss-loader",
"sass-loader",
],
},
{
test: /\.svg$/i,
type: "asset/inline",
},
{
test: /\.yarn$/i,
type: "asset/source",
},
{
test: /\.txt$/i,
type: "asset/source",
},
{
test: /\.(png|jpe?g)$/i,
type: "asset/resource",
},
],
},
optimization: {
splitChunks: {
chunks: "all",
},
},
};
};