-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.node.config.ts
125 lines (122 loc) · 3.72 KB
/
webpack.node.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
123
124
125
import { Configuration } from "webpack";
import { parse, resolve } from "path";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import { glob } from "glob";
import nodeExternals from "webpack-node-externals";
import { getConfigForTestScript, Mode, useEntrypoint } from "./webpack.config";
export default (env: Record<string, string | boolean>) => {
const mode = env.production === true ? "production" : "development";
return [
getConfigForNodeExtension(mode),
getConfigForNodeTests(mode),
getConfigForTestScript(mode),
];
};
export const getConfigForNodeExtension = (mode: Mode): Configuration => {
return {
mode: mode,
target: "node",
name: "extension:node",
entry: useEntrypoint("node"),
output: {
filename: "extension.js",
libraryTarget: "commonjs2",
path: resolve(__dirname, "out", "extension", "node"),
},
devtool: "eval-source-map",
resolve: {
extensions: [".ts", "..."],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/, /\.webworker.ts$/],
use: {
loader: "ts-loader",
options: {
configFile: resolve(
__dirname,
"tsconfig.node.json"
),
},
},
},
],
},
externals: {
vscode: "commonjs vscode",
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ["extension.js"],
}),
],
};
};
export const getConfigForNodeTests = (mode: Mode): Configuration => {
return {
mode: mode,
target: "node",
name: "tests:node",
entry: {
"test-runner": resolve(__dirname, "test/runner.node.ts"),
...glob
.sync(
resolve(
__dirname,
"test/suite/**/?(!(*.webworker)).test.ts"
)
)
.reduce(function (
entries: Record<string, string>,
path: string
) {
entries["test-suite/" + parse(path).name] = path;
return entries;
},
{}),
},
output: {
filename: "[name].js",
libraryTarget: "commonjs2",
path: resolve(__dirname, "out", "tests", "node"),
},
devtool: "eval-source-map",
resolve: {
extensions: [".ts", "..."],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/, /\.webworker.ts$/],
use: {
loader: "ts-loader",
options: {
configFile: resolve(
__dirname,
"tsconfig.node.json"
),
},
},
},
],
},
externals: [{ vscode: "commonjs vscode" }, nodeExternals()],
externalsPresets: {
node: true,
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
"test-runner.js",
"test-suite/**",
],
}),
],
performance: {
hints: false,
},
};
};