This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
89 lines (78 loc) · 2.29 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
// @ts-check
"use strict";
const ReplacePlugin = require("replace-in-file-webpack-plugin");
const path = require("path");
/** @type {import('webpack').Configuration} */
const config = {
// vscode extensions run in a Node.js-context
// => https://webpack.js.org/configuration/node/
target: "node",
// => https://webpack.js.org/configuration/entry-context/
entry: "./src/extension.ts",
output: {
// Bundle is stored in the 'out' folder (check package.json)
// => https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, "out"),
filename: "extension.js",
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]"
},
devtool: "source-map",
externals: {
// The vscode-module is created on-the-fly and must be excluded.
// Add other modules that cannot be webpack'ed.
// => https://webpack.js.org/configuration/externals/
vscode: "commonjs vscode"
},
resolve: {
extensions: [".ts", ".js", ".json"]
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader"
}
]
}
]
},
plugins: [
/**
* `@typescript/vfs` uses `path.dirname(require.resolve('typescript'))`
* But webpack replaces this with `path.dirname(336)` which is invalid!
* => replace the original code with `eval()` to make it work
*
* See https://github.com/webpack/webpack/issues/1554
*/
new ReplacePlugin([
// This replaces the source code before compilation.
{
dir: "node_modules/@typescript/vfs/dist",
files: ["vfs.cjs.development.js", "vfs.esm.js"],
rules: [
{
// We carefully match this with parenthesis to avoid a recursion.
search: "(require.resolve('typescript'))",
replace: `(eval("require.resolve('typescript')"))`
}
]
},
{
dir: "node_modules/@typescript/vfs/dist",
files: ["vfs.cjs.production.min.js"],
rules: [
{
// The production build uses different quotes.
search: '(require.resolve("typescript"))',
replace: `(eval("require.resolve('typescript')"))`
}
]
}
])
]
};
module.exports = config;