-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
122 lines (114 loc) · 2.5 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
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
import type { Configuration } from "webpack"
import WatchedGlobEntries from "webpack-watched-glob-entries-plugin"
import BrowserSync from "browser-sync-webpack-plugin"
import { join } from "path"
delete process.env.TS_NODE_PROJECT
const isDevelopment = process.env.NODE_ENV === "development"
process.env.BUILD_FOLDER = isDevelopment ? "dist" : "build"
process.env.BUILD_FOLDER_PATH = join(__dirname, process.env.BUILD_FOLDER)
function AddFolderToEntries(entries: Record<string, string>){
return Object.fromEntries(Object.entries(entries).map(([name, path]) => {
const folder = path.split("/").at(-2)!
return [folder + "/" + name, path]
}))
}
const babelOptions = {
presets: [
[
"@babel/preset-env", {
targets: {
chrome: "94",
firefox: "102"
}
}
]
],
plugins: [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-optional-chaining"
]
} as const
const config: Configuration = {
mode: "production",
target: "web",
devtool: "source-map",
entry: {
...AddFolderToEntries(WatchedGlobEntries.getEntries(["src/scripts/*.ts"], {
absolute: true,
cwd: __dirname,
ignore: [
"src/index.pug",
"src/tsconfig.json"
]
})())
},
output: {
filename: "[name].js",
path: process.env.BUILD_FOLDER_PATH
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: babelOptions
},
{
loader: "ts-loader",
options: {
configFile: join(__dirname, "src/tsconfig.json"),
ignoreDiagnostics: [2732, 7006]
}
}
]
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: "babel-loader",
options: babelOptions
}
]
},
resolve: {
extensions: [".ts", ".js"]
}
}
if(isDevelopment || config.watch || process.argv.slice(2).some(arg => /-(w|-watch)/i.test(arg))){
config.plugins = [
new WatchedGlobEntries(),
new BrowserSync({
host: "localhost",
port: 3000,
files: [
"src/**/*.*"
],
ignore: [
"src/typings/**",
"src/**/*.ts",
"src/**/*.scss",
"src/tsconfig.json",
process.env.BUILD_FOLDER + "/**/*.html",
process.env.BUILD_FOLDER + "/**/*.js",
process.env.BUILD_FOLDER + "/**/*.map",
],
server: {
baseDir: process.env.BUILD_FOLDER_PATH,
index: "index.html",
routes: {
"/src": join(__dirname, "src")
}
},
watch: true,
minify: false,
notify: false,
open: false,
ui: false
})
]
}
export default config