esbuild
esbuild copied to clipboard
Is there any harm in marking all my dependencies and devDependencies from my package.json set to "external" (for Electron app)?
I have seen a few examples that use the concept of excluding library code from node modules during the compile/bundle process with the external option adding all package dependencies from the package.json. I am wondering if there is any harm in this or anything I need to be careful with? Below is the code I am using in my esbuild config script for an electron app. I build a list of externalPackages to exclude by reading the package.json and grabbing all dependencies and then adding to that list all the built in node modules.
Thoughts? Anything I could improve here or need to be mindful of? Bad idea? Good idea?
import { build } from 'esbuild';
import { readFileSync } from 'fs';
import nodeModule from 'node:module';
let { dependencies, devDependencies, peerDependencies } = JSON.parse(readFileSync('./package.json', 'utf8'));
let externalPackages = Object.keys(!dependencies ? {} : dependencies)
.concat(Object.keys(!devDependencies ? {} : devDependencies))
.concat(Object.keys(!peerDependencies ? {} : peerDependencies))
.concat(...nodeModule.builtinModules);
build({
...
external: externalPackages,
...
}).catch(() => process.exit(1));