-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.ts
88 lines (82 loc) · 2.94 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
/// <reference types="node" />
import * as path from 'node:path';
import { Configuration, EnvironmentPlugin, ProvidePlugin } from 'webpack';
// This doesn't work if it's not a require()
// eslint-disable-next-line @typescript-eslint/no-var-requires, unicorn/prefer-module
const extensionPackage = require('./package.json');
// eslint-disable-next-line unicorn/prefer-module
const projectRoot = __dirname;
const nodeConfig: Configuration = {
// VS Code client extensions run in Node context. See: https://webpack.js.org/configuration/node/
target: 'node',
// Leaves the source code as close as possible to the original (when packaging we set this to 'production')
mode: 'none',
// Entry point into extension (in package.json). See: https://webpack.js.org/configuration/entry-context/
entry: {
'extension.node': './src/extension.node.ts',
},
// Bundle output location. See: https://webpack.js.org/configuration/output/
output: {
filename: '[name].js',
path: path.join(projectRoot, 'dist'),
libraryTarget: 'commonjs',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
plugins: [
new EnvironmentPlugin({
EXTENSION_NAME: `${extensionPackage.publisher}.${extensionPackage.name}`,
EXTENSION_VERSION: extensionPackage.version,
}),
],
devtool: 'nosources-source-map',
// Support reading TypeScript and JavaScript files. See: https://github.com/TypeStrong/ts-loader
resolve: {
extensions: ['.ts', '.js'],
alias: {
src: path.resolve(projectRoot, 'src'),
},
},
// Modules that cannot be added through Webpack. See: https://webpack.js.org/configuration/externals/
externals: {
vscode: 'commonjs vscode', // ignored because 'vscode' module is created on the fly and doesn't really exist
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
},
],
},
],
},
performance: {
hints: false,
},
infrastructureLogging: {
level: 'log', // enables logging required for problem matchers
},
};
const browserConfig: Configuration = {
// extensions run in a webworker context
...nodeConfig,
target: 'webworker',
entry: {
'extension.web': './src/extension.web.ts',
// 'test/suite/index': './src/web/test/suite/index.ts',
},
resolve: {
...nodeConfig.resolve,
mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules
},
plugins: [
new ProvidePlugin({
process: 'process/browser', // provide a shim for the global `process` variable
}),
],
};
// eslint-disable-next-line unicorn/prefer-module
module.exports = [nodeConfig, browserConfig];