-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
96 lines (90 loc) · 2.32 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const path = require("path");
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require("webpack-node-externals");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const { ProvidePlugin } = require("webpack");
const webpack = require('webpack');
const libsToExcludeFromCompilation = [
"webpack",
"webpack-virtual-modules",
"webpack-node-externals",
"handlebars",
"express",
"@swc/core",
"swc-loader",
"ts-loader",
"fork-ts-checker-webpack-plugin"
]
const config = {
entry: path.join(__dirname, "src", "index.ts"),
target: "node",
externalsPresets: { node: true },
externals: [nodeExternals({
allowlist: (modulePath) => {
console.log(modulePath);
return !(libsToExcludeFromCompilation.includes(modulePath));
}
})],
output: {
filename: "index.js",
path: path.join(__dirname, "dist"),
libraryTarget: "umd",
globalObject: "this"
},
module: {
rules: [
{
test: /\.(jsx?)|(tsx?)$/,
exclude: /(node_modules|bower_components)/,
use: ["babel-loader", "ts-loader"]
},
{
test: /\.hbs$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: path.resolve('handlebars-loader.js'),
}
},
]
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
},
watchOptions: {
aggregateTimeout: 600,
ignored: /node_modules/,
},
optimization: {
minimize: false
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false,
cleanOnceBeforeBuildPatterns: [path.resolve(__dirname, "./dist")],
}),
new ProvidePlugin({
"Handlebars": "handlebars",
})
]
}
// Fix issues with importing unsupported fsevents module in Windows and Linux
// For more info, see: https://github.com/vinceau/project-clippi/issues/48
if (process.platform !== "darwin") {
config.plugins.push(
new webpack.IgnorePlugin({
resourceRegExp: /^fsevents$/,
})
);
}
module.exports = (env, argv) => {
const isProduction = argv.mode === "production";
if (isProduction) {
config.mode = "production";
config.devtool = "source-map";
} else {
config.mode = "development";
config.devtool = "cheap-module-source-map";
}
return config;
};