-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
63 lines (57 loc) · 1.68 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
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
'use strict';
const path = require('path');
async function getExtensionConfig(target, mode, env) {
return {
name: `extension:${target}`,
entry: './src/extension.ts',
target: target,
mode: mode,
devtool: 'nosources-source-map',
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/
// modules added here also need to be added in the .vsceignore file
},
output: {
path: target === 'webworker' ? path.join(__dirname, 'dist', 'browser') : path.join(__dirname, 'dist'),
filename: 'extension.js',
libraryTarget: 'commonjs2'
},
resolve: {
// support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js'],
alias:
target === 'webworker' ? { 'node-fetch': 'cross-fetch' } : undefined,
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
}
};
}
module.exports = /**
* @param {{ esbuild?: boolean; } | undefined } env
* @param {{ mode: 'production' | 'development' | 'none' | undefined; }} argv
* @returns { Promise<WebpackConfig[]> }
*/
async function (env, argv) {
const mode = argv.mode || 'none';
env = {
esbuild: false,
...env,
};
return Promise.all([
getExtensionConfig('node', mode, env),
getExtensionConfig('webworker', mode, env),
]);
};