/
webpack.config.ts
129 lines (124 loc) · 3.63 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
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
/* eslint-disable import/no-import-module-exports */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable import/no-extraneous-dependencies */
// @ts-check
import CircularDependencyPlugin from 'circular-dependency-plugin';
import path from 'node:path';
import type webpack from 'webpack';
import { DefinePlugin } from 'webpack';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const generateConfig = (env: any): webpack.Configuration => ({
target: 'node', // vscode extensions run in a Node.js-context 📖 ->
// https://webpack.js.org/configuration/node/
context: __dirname,
entry: {
extension: './src/extension/extension.ts',
remoteCli: './src/tools/remoteCli.ts',
syntaxDump: './src/tools/syntaxDump.ts',
},
plugins: [
new CircularDependencyPlugin({
exclude: /node_modules/,
// eslint-disable-next-line unicorn/better-regex
include: /.*.ts/,
failOnError: true,
}),
new DefinePlugin({
PACKAGE_VERSION: JSON.stringify(require('./package.json').version),
}),
],
output: {
// the bundle is stored in the 'dist' folder (check package.json), 📖 ->
// https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
devtool: 'source-map',
optimization: {
minimize: false,
mangleExports: false,
concatenateModules: false,
chunkIds: 'named',
moduleIds: 'named',
removeAvailableModules: false,
removeEmptyChunks: false,
flagIncludedChunks: false,
providedExports: false,
// this one is needed, otherwise bundle can't be loaded because of resolving nodejs
usedExports: false,
},
externals: [
{
vscode: 'commonjs vscode', // 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/
},
/Debug\/iconv\.node/,
/Debug\/nodegit.node/,
'../package',
// these 2 trigger "Module not found" warning in webpack (deps of "ws")
'bufferutil',
'utf-8-validate',
// add native modules which cause trouble with webpack
'node-window-manager',
// otherwise webpack inlines lib/README.md from nodegit
/.*\.md$/,
],
resolve: {
// support reading TypeScript and JavaScript files, 📖 ->
// https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js', '.node'],
},
module: {
// becaues of `typescript-collections`
noParse: [/.*umd\.js/, /.*\.md$/],
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
module: 'es2020', // override `tsconfig.json` so that TypeScript
// emits native JavaScript modules.
noUnusedLocals: false,
},
},
},
{ loader: 'ifdef-loader', options: { DEBUG: env?.DEBUG } },
],
},
{
test: /\.node$/,
use: 'node-loader',
exclude: ['/Debug/iconv.node', /.*build\/Debug.*/],
},
],
},
ignoreWarnings: [
{
message: /Can't resolve 'spawn-sync'/,
},
{
// nodegit
message: /Can't resolve '\.\/deprecated/,
},
{
message: /build\/Debug/,
},
{
message: /the request of a dependency is an expression/,
},
],
stats: {
all: false,
errors: true,
warnings: true,
},
});
module.exports = (env: unknown) => generateConfig(env);