-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
90 lines (87 loc) · 2.19 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
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const LessImportPrefix = require("./src/less/import-prefix");
const ImportResolver = require("./src/resolver/import-resolver");
const entries = {
less: "./src/less/index.ts",
loader: "./src/loader/index.ts",
resolver: "./src/resolver/index.ts",
};
const HTMLPlugins = Object.keys(entries).map(
key =>
new HtmlWebpackPlugin({
filename: `${key}.html`,
template: path.resolve("./public/index.html"),
chunks: [key],
scriptLoading: "defer",
inject: "body",
})
);
/**
* @typedef {import("webpack").Configuration} WebpackConfig
* @typedef {import("webpack-dev-server").Configuration} WebpackDevServerConfig
* @type {WebpackConfig & {devServer?: WebpackDevServerConfig}}
*/
module.exports = {
context: __dirname,
mode: process.env.NODE_ENV,
entry: entries,
output: {
filename: "[name].[contenthash].js",
path: path.resolve(__dirname, "build"),
},
resolve: {
extensions: [".js", ".ts"],
alias: {
"@": path.join(__dirname, "./src"),
},
plugins: [new ImportResolver()],
},
stats: "minimal",
devServer: {
hot: true,
compress: true,
port: 3000,
},
module: {
rules: [
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "less-loader",
options: {
plugins: [new LessImportPrefix(["@arco-design/web-react"])],
},
},
require.resolve("./src/loader/import-loader"),
],
},
{
test: /\.ts$/,
use: ["babel-loader", "ts-loader"],
exclude: /node_modules/,
},
],
},
plugins: [
new HtmlWebpackPlugin({
filename: `index.html`,
template: path.resolve("./public/index.html"),
chunks: [],
scriptLoading: "defer",
}),
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
chunkFilename: "[id].[contenthash].css",
}),
...HTMLPlugins,
],
optimization: {
moduleIds: "deterministic",
chunkIds: "deterministic",
},
};