-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
81 lines (75 loc) · 2.41 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
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const path = require("path");
const r = (location) => path.resolve(__dirname, location);
/** @type {webpack.Configuration} */
module.exports = {
target: "web",
mode: "none", // Leave source code as close as possible. Only set to production during distribution.
entry: "./src/main.ts",
output: {
path: r("dist"),
filename: "[contenthash].[name].js",
},
devtool: "nosources-source-map",
resolve: {
extensions: [".tsx", ".ts", ".js"],
fallback: {
"buffer": require.resolve("buffer"),
"crypto": require.resolve("crypto-browserify"),
"os": require.resolve("os-browserify/browser"),
"stream": require.resolve("stream-browserify"),
},
},
node: {
__dirname: 'mock',
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
configFile: r("tsconfig.web.json"),
},
},
],
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.(ttf)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: '',
publicPath: '..',
postTransformPublicPath: (p) => `__webpack_public_path__ + ${p}`,
}
},
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: "[contenthash].[name].css",
chunkFilename: "[id].css",
}),
new HtmlWebpackPlugin({ template: "index.html", cache: false }),
// Work around for Buffer is undefined:
// https://github.com/webpack/changelog-v5/issues/10
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
};