forked from microsoft/vscode-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
66 lines (56 loc) · 1.59 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
'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
'node-usb-native', 'usb-detection', '@serialport/bindings', 'bindings', 'serialport'];
for (const mod of unbundledModule) {
const p = 'node_modules/' + mod;
fs.copySync(p, 'out/node_modules/' + mod);
}
const list = getDependeciesFromNpm(mod);
const moduleList = list.filter((value, index, self) => {
return self.indexOf(value) === index && unbundledModule.indexOf(value) === -1 && !/^@types\//.test(value);
});
for (const mod of moduleList) {
entry[mod] = './node_modules/' + mod;
}
return entry;
}
function getDependeciesFromNpm(mod) {
let list = [];
const deps = mod.dependencies;
if (!deps) {
return list;
}
for (const m of Object.keys(deps)) {
list.push(m);
list = list.concat(getDependeciesFromNpm(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.exports = config;