This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
/
webpack.config.js
88 lines (78 loc) · 2.5 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
'use strict';
const path = require('path');
const cp = require('child_process');
const fs = require('fs-plus');
function getEntry() {
const entry = {};
const npmListRes = cp.execSync('npm list -only prod -json', {
encoding: 'utf8'
});
const mod = JSON.parse(npmListRes);
const unbundledModule = ['impor', 'uuid',
// usb-native modules can not be bundled
// that caused the extension to not work.
'usb-detection', 'bindings'];
for (const mod of unbundledModule) {
const p = 'node_modules/' + mod;
fs.copySync(p, 'out/node_modules/' + mod);
}
// The nan module is nested inside usb-detection, so it was already copied.
const noEntryModules = unbundledModule.concat(['nan']);
const list = getDependenciesFromNpm(mod);
const moduleList = list.filter((value, index, self) => {
// Some entries in the list of unbundled modules are really namespaces, so
// we do a prefix match to see if the module should be excluded. This isn't
// perfect, but works for the set of modules we care about.
return self.indexOf(value) === index && noEntryModules.filter(m => value.startsWith(m)).length === 0 && !/^@types\//.test(value);
});
for (const mod of moduleList) {
entry[mod] = './node_modules/' + mod;
}
return entry;
}
function getDependenciesFromNpm(mod) {
let list = [];
const deps = mod.dependencies;
if (!deps) {
return list;
}
for (const m of Object.keys(deps)) {
list.push(m);
list = list.concat(getDependenciesFromNpm(deps[m]));
}
return list;
}
/**@type {import('webpack').Configuration}*/
const config = {
target: 'node',
entry: getEntry(),
output: {
path: path.resolve(__dirname, 'out/node_modules'),
filename: '[name].js',
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "../[resource-path]",
},
externals: {
vscode: "commonjs vscode",
},
resolve: {
extensions: ['.js', '.json']
},
module: {
rules: [
// For some reason, webpack 4 was unable to bundle the
// telemetryReporter.node.min.js file. Babel seems to handle it, so
// use that as a workaround until we can upgrade to webpack 5.
{
test: /telemetryReporter\.node\.min\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
}
}
module.exports = config;