-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
rollup-plugins.js
60 lines (55 loc) · 1.57 KB
/
rollup-plugins.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
const { startService } = require('esbuild');
const path = require('path');
function linkVlsInCLI() {
return {
name: 'link-vls-in-cli',
resolveId(source, importer) {
if (source === './services/vls') {
return { id: './vls.js', external: true };
}
return null;
}
};
}
function bundleVlsWithEsbuild() {
/**
* @type {import('esbuild').Service | null}
*/
let service = null;
const getServerURL = url => path.resolve(__dirname, '../server', url);
return {
name: 'bundle-vls-with-esbuild',
async buildStart() {
// watch src changed
this.addWatchFile(getServerURL('src/'));
if (!service) {
// hack with esbuild and vscode debugger
const oldCwd = process.cwd;
process.cwd = () => getServerURL('../');
service = await startService();
process.cwd = oldCwd;
}
console.log(`bundles ${getServerURL('src/main.ts')} with esbuild`);
await service.build({
entryPoints: [getServerURL('src/main.ts')],
outfile: getServerURL('dist/vls.js'),
minify: true,
bundle: true,
sourcemap: true,
platform: 'node',
mainFields: ['module,main'],
target: 'es2018',
external: ['vscode', 'eslint-plugin-vue', 'stylus', 'eslint'],
format: 'cjs',
tsconfig: getServerURL('tsconfig.json')
});
console.log(`✨ success with esbuild`);
},
async buildEnd() {
if (!process.env.ROLLUP_WATCH) {
service.stop();
}
}
};
}
module.exports = { linkVlsInCLI, bundleVlsWithEsbuild };