-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from afonsonf/add-build-using-esbuild
Introduce bundling with esbuild
- Loading branch information
Showing
13 changed files
with
620 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
src/**/* | ||
.devcontainer/ | ||
.github/ | ||
.vscode/ | ||
.vscode-test/ | ||
# include languages/ | ||
node_modules/ | ||
out/src/ | ||
out/tests/ | ||
tests/ | ||
scripts/ | ||
**/*.map | ||
**/tsconfig.json | ||
**/tslint.json | ||
**/*.code-workspace | ||
out/main.js.map | ||
# include out/main.js | ||
resources/images/screencast.gif | ||
version | ||
# include resources/ | ||
src/ | ||
tests/ | ||
# include tools/ | ||
.eslintignore | ||
.eslintrc.json | ||
.gitignore | ||
.sonarcloud.properties | ||
.travis.yml | ||
.github/**/* | ||
.vscode/**/* | ||
# include CHANGELOG.md | ||
CONTRIBUTING.md | ||
esbuild.js | ||
# include LICENSE.md | ||
# include package-lock.json package.json | ||
# include README.md | ||
tsconfig.json | ||
version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable no-undef */ | ||
const { build } = require('esbuild'); | ||
|
||
//@ts-check | ||
/** @typedef {import('esbuild').BuildOptions} BuildOptions **/ | ||
|
||
const args = process.argv.slice(2); | ||
|
||
/** @type BuildOptions */ | ||
const baseConfig = { | ||
bundle: true, | ||
minify: args.includes('--production'), | ||
sourcemap: !args.includes('--production'), | ||
}; | ||
|
||
// Config for extension source code (to be run in a Node-based context) | ||
/** @type BuildOptions */ | ||
const extensionConfig = { | ||
...baseConfig, | ||
platform: 'node', | ||
format: 'cjs', | ||
entryPoints: ['./src/main.ts'], | ||
outfile: './out/main.js', | ||
external: ['vscode'], | ||
}; | ||
|
||
// This watch config adheres to the conventions of the esbuild-problem-matchers | ||
// extension (https://github.com/connor4312/esbuild-problem-matchers#esbuild-via-js) | ||
/** @type BuildOptions */ | ||
const watchConfig = { | ||
watch: { | ||
onRebuild(error) { | ||
console.log('[watch] build started'); | ||
if (error) { | ||
error.errors.forEach((error) => | ||
console.error( | ||
`> ${error.location.file}:${error.location.line}:${error.location.column}: error: ${error.text}` | ||
) | ||
); | ||
} else { | ||
console.log('[watch] build finished'); | ||
} | ||
}, | ||
}, | ||
}; | ||
|
||
// Build script | ||
(async () => { | ||
try { | ||
if (args.includes('--watch')) { | ||
// Build and watch extension | ||
console.log('[watch] build started'); | ||
await build({ | ||
...extensionConfig, | ||
...watchConfig, | ||
}); | ||
console.log('[watch] build finished'); | ||
} else { | ||
// Build extension | ||
await build(extensionConfig); | ||
console.log('build complete'); | ||
} | ||
} catch (err) { | ||
process.stderr.write(err.stderr); | ||
process.exit(1); | ||
} | ||
})(); |
Oops, something went wrong.