diff --git a/bundle.js b/bundle.js new file mode 100644 index 00000000..0c0c32d2 --- /dev/null +++ b/bundle.js @@ -0,0 +1,45 @@ +'use strict'; + +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable no-process-exit */ +/* eslint-disable node/no-unpublished-require */ + +const fs = require('fs-extra'); +const esbuild = require('esbuild'); +const glob = require('fast-glob'); + +const args = new Set(process.argv.slice(2)); + +async function bundle() { + const entryPoints = [ + 'index.js', + 'server.js', + // Necessary because bundler cannot recognize lazy loads in + // https://github.com/stylelint/stylelint/blob/13.13.1/lib/syntaxes/index.js#L9-L15 + ...(await glob('node_modules/stylelint/lib/syntaxes/syntax-*.js')), + ]; + + for (const path of await glob('dist/*')) { + await fs.remove(path); + } + + try { + await esbuild.build({ + entryPoints, + entryNames: '[name]', + bundle: true, + outdir: 'dist', + external: ['vscode'], + format: 'cjs', + platform: 'node', + logLevel: 'info', + watch: args.has('--watch'), + sourcemap: args.has('--sourcemap'), + minify: args.has('--minify'), + }); + } catch { + process.exit(1); + } +} + +bundle(); diff --git a/package.json b/package.json index 1e20e8ee..622679ce 100644 --- a/package.json +++ b/package.json @@ -233,7 +233,7 @@ }, "scripts": { "ci:download-vscode": "node ci-download-vscode.js", - "bundle-base": "esbuild ./index.js ./server.js --bundle --outdir=dist --external:vscode --format=cjs --platform=node", + "bundle-base": "node bundle.js", "bundle": "npm run bundle-base -- --sourcemap", "bundle-watch": "npm run bundle-base -- --sourcemap --watch", "format": "prettier . --write",