Skip to content

Commit cbb94a4

Browse files
authored
feat(build): using esbuild instead webpack (#107)
1 parent 08e931b commit cbb94a4

File tree

6 files changed

+68
-885
lines changed

6 files changed

+68
-885
lines changed

.husky/pre-commit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
npm run lint-fix
5-
git add .
4+
# eslint fix if lint fail then abort commit
5+
npm run lint || (npm run lint-fix && exit 1)

.vim/coc-settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@
1010
"conceallevel",
1111
"cursorcolumn",
1212
"cursorline",
13+
"esbuild",
1314
"foldcolumn",
1415
"getlog",
1516
"outchannel",
17+
"outfile",
1618
"pubspec",
1719
"regist",
1820
"relativenumber",
1921
"signcolumn",
22+
"sourcemap",
2023
"winhighlight"
2124
]
2225
}

esbuild.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
async function start(watch) {
3+
await require('esbuild').build({
4+
entryPoints: ['src/index.ts'],
5+
bundle: true,
6+
watch,
7+
minify: process.env.NODE_ENV === 'production',
8+
sourcemap: process.env.NODE_ENV === 'development',
9+
define: {},
10+
mainFields: ['module', 'main'],
11+
external: ['coc.nvim'],
12+
platform: 'node',
13+
// keep same node version which coc.nvim support
14+
target: 'node10.12',
15+
outfile: 'out/index.js',
16+
plugins: [],
17+
});
18+
}
19+
20+
let watch = false;
21+
22+
if (process.argv.length > 2 && process.argv[2] === '--watch') {
23+
console.log('watching...');
24+
watch = {
25+
onRebuild(error) {
26+
if (error) {
27+
console.error('watch build failed:', error);
28+
} else {
29+
console.log('watch build succeeded');
30+
}
31+
},
32+
};
33+
}
34+
35+
start(watch)
36+
.then(() => {
37+
console.log('build succeeded');
38+
})
39+
.catch(() => {
40+
console.error('build failed');
41+
});

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
},
1717
"scripts": {
1818
"clean": "rm -rf ./out",
19-
"watch": "webpack --watch",
20-
"build": "webpack",
19+
"watch": "NODE_ENV=development node esbuild.js --watch",
20+
"build": "NODE_ENV=production node esbuild.js",
2121
"lint": "eslint src",
2222
"lint-fix": "eslint --fix src",
2323
"prepare": "husky install && npm run clean && npm run build"
@@ -217,22 +217,20 @@
217217
]
218218
},
219219
"devDependencies": {
220-
"@types/node": "^14.14.31",
220+
"@types/node": "^10.12.0",
221221
"@typescript-eslint/eslint-plugin": "^4.16.1",
222222
"@typescript-eslint/parser": "^4.16.1",
223223
"coc.nvim": "^0.0.80",
224224
"colors": "^1.4.0",
225+
"esbuild": "^0.9.0",
225226
"eslint": "^7.21.0",
226227
"eslint-config-prettier": "^8.1.0",
227228
"eslint-plugin-prettier": "^3.3.1",
228229
"fast-glob": "^3.2.5",
229230
"husky": "^5.1.3",
230231
"prettier": "^2.2.1",
231-
"ts-loader": "^8.0.17",
232232
"typescript": "^4.2.2",
233233
"vscode-languageserver-protocol": "^3.16.0",
234-
"webpack": "^5.24.2",
235-
"webpack-cli": "^4.5.0",
236234
"which": "^2.0.2"
237235
}
238236
}

webpack.config.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)