Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include or exclude folder 'node_modules' with esbuild

I am using esbuild to build a Visual Studio Code extension. The build gives a warning like:

✨  Done in 1.28s.
This extension consists of 7026 files, out of which 5430 are JavaScript files. For performance reasons, you should bundle your extension: https://aka.ms/vscode-bundle-extension . You should also exclude unnecessary files by adding them to your .vscodeignore: https://aka.ms/vscode-vscodeignore
 DONE  Packaged: /my-vscode/my-vscode-0.0.2.vsix (7026 files, 8.43MB)

Does folder node_modules need to be added to .vscodeignore?

When I tried doing it and installed the plugin, I get an error that my commands are not found...

like image 800
Kamesh Avatar asked Jan 01 '26 07:01

Kamesh


1 Answers

You can pass the external keyword in your esbuild config to exclude certain modules (or all of them using an asterisk *). For example, the following will exclude the pg, sqlite3, tedious, pg-hstore modules from your build process:

const { nodeExternalsPlugin } = require("esbuild-node-externals");

esbuild
    .build({
      entryPoints: [entryFile],
      outfile: outFile,
      minify: true,
      bundle: true,
      target: TARGET,
      plugins: [copyPlugin, nodeExternalsPlugin()],
      sourcemap: true,
      platform: "node",
      define,
      external: ["pg", "sqlite3", "tedious", "pg-hstore"],
    })
    .then((r) => {
      console.log(`Build ${entryFile} to ${outFile} succeeded.`);
    })
    .catch((e) => {
      console.log("Error building:", e.message);
      process.exit(1);
    });
like image 97
zelusp Avatar answered Jan 04 '26 20:01

zelusp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!