-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
97 lines (91 loc) · 2.26 KB
/
webpack.config.ts
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
import Path from "path";
import type Webpack from "webpack";
import HtmlBundler from "html-webpack-plugin";
import CssExtractor from "mini-css-extract-plugin";
import TsPathParser from "tsconfig-paths-webpack-plugin";
import tsPaths2Alias from "./tsPaths2Alias";
const env = process.env.NODE_ENV ?? "production";
if (env !== "development" && env !== "production") {
throw new TypeError("NODE_ENV must be either development or production.");
}
const context = Path.resolve(__dirname, "src");
const resourcePath = "/";
const outputPath = Path.resolve(__dirname, `build${resourcePath}`);
const config: Webpack.Configuration = {
mode: env,
context,
entry: "./index.ts",
output: {
filename: "index.js",
path: outputPath,
publicPath: resourcePath,
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
// doesn't work on linux
plugins: [
new TsPathParser(),
],
// work on both linux and windows
// alias: tsPaths2Alias(),
// work on both linux and windows
// alias: {
// css: Path.resolve(__dirname, "src/styles/css"),
// "/images/pages/search": Path.resolve(__dirname, "src/styles/images"),
// },
},
plugins: [
new HtmlBundler({
template: "./index.html",
hash: true,
}),
new CssExtractor({
filename: "index.css",
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
"ts-loader",
]
},
{
test: /\.(sc|sa|c)ss?$/,
exclude: /node_modules/,
use: [
CssExtractor.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
url: (url: string) => !url.match(/openimage|xmlns/),
}
},
"resolve-url-loader",
{
loader: "sass-loader",
options: {
/**
* for resolve-url-loader to be able to parse relative url
*/
sourceMap: true,
}
}
]
},
{
test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)$/i,
type: "asset/resource",
}
]
},
stats: {
builtAt: true,
timings: true,
modules: false,
},
};
export default config;