-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.ts
85 lines (79 loc) · 2.71 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
import path from "path";
import fs from "fs-extra";
import { Configuration, DefinePlugin } from "webpack";
import copyWebpackPlugin from "copy-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import WebpackBar from "webpackbar";
const buildMode = process.argv[3] == "production" ? "production" : "development";
const isProductionBuild = buildMode === "production";
const pf2eSystemPath = (() => {
const configPath = path.resolve(process.cwd(), "foundryconfig.json");
const configData = fs.existsSync(configPath) ? fs.readJSONSync(configPath) : undefined;
return configData !== undefined ? path.join(configData.dataPath, "Data", "modules", configData.moduleName) : null;
})();
const outDir = pf2eSystemPath ?? path.join(__dirname, "dist/");
console.log(`Destination Folder set to ${outDir}`);
const config: Configuration = {
context: __dirname,
mode: buildMode,
entry: "./src/index.ts",
module: {
rules: [
{
test: /\.ts$/,
use: [
{
loader: "ts-loader",
options: {
configFile: path.resolve(__dirname, "tsconfig.json"),
transpileOnly: true,
happyPackMode: true,
compilerOptions: {
noEmit: false,
}
}
}
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
url: false,
sourceMap: true,
},
},
{
loader: "sass-loader",
options: { sourceMap: true },
},
],
}
]
},
devtool: isProductionBuild ? undefined : "inline-source-map",
watch: !isProductionBuild,
plugins: [
new ForkTsCheckerWebpackPlugin({ typescript: { memoryLimit: 4096 } }),
new DefinePlugin({
BUILD_MODE: JSON.stringify(buildMode),
}),
new copyWebpackPlugin({
patterns: [{ from: "README.md" }, { from: "module.json" }],
}),
new WebpackBar({}),
],
resolve: {
extensions: [".ts"],
},
output: {
clean: { keep: "packs" },
path: outDir,
filename: "index.js",
},
};
export default config;