-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collect data about external modules #905
Comments
I think I understand what you’re trying to do. Instead of looking at package.json and marking all known dependencies as external, something I’ve done previously: // Dependencies describes dependencies abstractly.
type Dependencies = { [key: string]: string }
// Package describes package.json (only dependencies).
interface Package {
dependencies: Dependencies
peerDependencies: Dependencies
devDependencies: Dependencies
}
async function external(): Promise<string[]> {
// NOTE: Use try-catch to suppress esbuild dynamic require warning.
let pkg: Package
try {
pkg = require(path.resolve("package.json"))
} catch {
return []
}
const deps = Object.keys(pkg!.dependencies ?? {})
const peerDeps = Object.keys(pkg!.peerDependencies ?? {})
const devDeps = Object.keys(pkg!.devDependencies ?? {})
// Return distinct dependencies:
return [...new Set([...deps, ...peerDeps, ...devDeps])]
} It sounds like you want a more programmatic approach by looking at Btw it looks like
So are you specifically proposing you want / need this API: |
It would be useful to know which of the modules defined as
external
were actually required in a build, if any, allowing us to know which modules to package separately.I've looked at the
metafile
parameter, but it doesn't seem to contain any information about external modules.Instead of using
external
, I could transform the array of module names into a regular expression and use it in a plugin which, for any of those modules, will returnexternal: true
and add the module name to an internal structure.I was trying to avoid the performance penalty of using a plugin, so I was wondering if you'd consider adding this functionality to the core. If so, I'm happy to work on a PR.
Thanks!
The text was updated successfully, but these errors were encountered: