forked from xdy/xdy-pf2e-workbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
160 lines (154 loc) · 5.15 KB
/
webpack.config.ts
File metadata and controls
160 lines (154 loc) · 5.15 KB
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
152
153
154
155
156
157
158
159
160
//Adapted from https://gitlab.com/hooking/foundry-vtt---pathfinder-2e/-/blob/master/webpack.config.ts
import * as fs from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as process from "process";
import { Configuration, DefinePlugin } from "webpack";
import copyWebpackPlugin from "copy-webpack-plugin";
import CssMinimizerPlugin from "css-minimizer-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
import SimpleProgressWebpackPlugin from "simple-progress-webpack-plugin";
const buildMode = process.argv[3] === "production" ? "production" : "development";
const isProductionBuild = buildMode === "production";
const outDir = (() => {
const configPath = path.resolve(process.cwd(), "foundryconfig.json");
const config = fs.readJSONSync(configPath, { throws: false });
return config instanceof Object
? path.join(config.dataPath, "Data", "modules", "xdy-pf2e-workbench")
: path.join(__dirname, "dist/");
})();
type Optimization = Configuration["optimization"];
const optimization: Optimization = isProductionBuild
? {
minimize: false,
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: false,
},
}),
new CssMinimizerPlugin(),
],
splitChunks: {
chunks: "all",
cacheGroups: {
default: {
name: "xdy-pf2e-workbench",
test: "src/module/xdy-pf2e-workbench.ts",
},
vendor: {
name: "vendor",
test: /node_modules/,
},
},
},
}
: undefined;
const config: Configuration = {
context: __dirname,
mode: buildMode,
entry: {
main: "./src/module/xdy-pf2e-workbench.ts",
},
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
configFile: path.resolve(__dirname, "tsconfig.json"),
experimentalWatchApi: !isProductionBuild,
happyPackMode: true,
transpileOnly: true,
compilerOptions: {
noEmit: false,
},
},
},
],
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
url: false,
sourceMap: true,
},
},
{
loader: "sass-loader",
options: { sourceMap: true },
},
],
},
{
test: /nouislider\.min\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
url: false,
sourceMap: true,
},
},
],
},
{
loader: "thread-loader",
options: {
workers: os.cpus().length + 1,
poolRespawn: false,
poolTimeout: isProductionBuild ? 500 : Infinity,
},
},
],
},
optimization: optimization,
devtool: isProductionBuild ? undefined : "inline-source-map",
bail: isProductionBuild,
watch: !isProductionBuild,
plugins: [
new ForkTsCheckerWebpackPlugin({ typescript: { memoryLimit: 4096 } }),
new DefinePlugin({
BUILD_MODE: JSON.stringify(buildMode),
}),
new copyWebpackPlugin({
patterns: [
{ from: "module.json" },
{
from: "packs/**",
noErrorOnMissing: true
},
{
from: "static/",
transform(content: Buffer, absoluteFrom: string) {
if (path.basename(absoluteFrom) === "en.json") {
return JSON.stringify(JSON.parse(content.toString()));
}
return content;
},
},
],
}),
new MiniCssExtractPlugin({ filename: "styles/[name].css" }),
new SimpleProgressWebpackPlugin({ format: "compact" }),
],
resolve: {
extensions: [".ts"],
},
output: {
clean: true,
path: outDir,
filename: "xdy-pf2e-workbench.bundle.js",
},
};
// eslint-disable-next-line import/no-default-export
export default config;