-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
132 lines (122 loc) · 3.06 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
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
130
131
132
// @ts-check
'use strict';
// Imports
const glob = require('glob');
// Types
/** @typedef {import('webpack').Configuration} Configuration */
/** @typedef {NonNullable<Configuration['context']>} CustomContext */
/** @typedef {{[index: string]: string}} CustomExternals */
/** @typedef {NonNullable<Configuration['resolve']>} CustomResolve */
/**
* @typedef
* {Configuration & {context: CustomContext, externals: CustomExternals, resolve: CustomResolve}}
* BaseConfiguration
*/
// Variables
/** @type BaseConfiguration */
const baseConfig = {
context: __dirname,
devtool: 'nosources-source-map',
externals: {
'@vscode/test-electron': 'commonjs @vscode/test-electron',
jasmine: 'commonjs jasmine',
vscode: 'commonjs vscode',
},
mode: 'none',
module: {
rules: [
{
exclude: /node_modules/,
test: /\.ts$/,
use: [{loader: 'ts-loader'}],
},
],
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs',
path: `${__dirname}/dist`,
},
performance: {
hints: false,
},
resolve: {
extensions: ['.ts', '.js'],
// See https://webpack.js.org/configuration/resolve/#resolvefallback.
fallback: {
buffer: require.resolve('buffer'),
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
},
mainFields: ['module', 'main'],
},
stats: 'minimal',
target: 'node',
};
/** @type BaseConfiguration */
const baseWebConfig = {
...baseConfig,
target: 'webworker',
externals: {
vscode: 'commonjs vscode',
},
resolve: {
...baseConfig.resolve,
mainFields: ['browser', ...(baseConfig.resolve.mainFields || [])],
},
};
/** @type Configuration */
const extensionConfig = {
...baseConfig,
name: 'extension',
entry: {
extension: './src/extension.ts',
},
};
/** @type Configuration */
const extensionWebConfig = {
...baseWebConfig,
name: 'extensionWeb',
entry: {
'extension-web': './src/extension.ts',
},
};
/** @type Configuration */
const testsUnitConfig = {
...baseConfig,
name: 'testsUnit',
entry: {
'test/run-tests-unit': './src/test/run-tests-unit.ts',
'test/unit/index.spec': glob.sync(`${baseConfig.context}/src/test/unit/**/*.ts`),
},
externals: Object.
fromEntries(Object.
entries(baseConfig.externals).
filter(([name]) => name !== 'vscode')),
resolve: {
...baseConfig.resolve,
alias: {
...baseConfig.resolve.alias,
// `vscode` APIs are only provided when running tests through VSCode (i.e. e2e tests).
// For "standalone" unit tests, we need to mock them.
vscode$: `${__dirname}/src/test/helpers/vscode.mock.ts`,
},
},
};
/** @type Configuration */
const testsE2eConfig = {
...baseConfig,
name: 'testsE2e',
entry: {
'test/e2e/index.spec': glob.sync(`${baseConfig.context}/src/test/e2e/**/*.ts`),
'test/helpers/e2e-runner': './src/test/helpers/e2e-runner.ts',
'test/run-tests-e2e': './src/test/run-tests-e2e.ts',
},
};
// Exports
module.exports = [
extensionConfig,
extensionWebConfig,
testsUnitConfig,
testsE2eConfig,
];