diff --git a/src/cli.ts b/src/cli.ts index 69e2cbc50..2f83c5889 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -16,6 +16,7 @@ cli .option('--target ', 'Bundle target, "es20XX" or "esnext"', { default: 'es2017', }) + .option('--bundle', 'Bundle node_modules') .option('--watch', 'Watch mode') .action(async (files: string[], options) => { const { rollup, watch } = await import('rollup') @@ -28,7 +29,7 @@ cli input: files, plugins: [ hashbangPlugin(), - resolvePlugin(), + resolvePlugin({ bundle: options.bundle }), commonjsPlugin(), esbuildPlugin({ minify: options.minify, target: options.target }), ], diff --git a/src/resolve-plugin.ts b/src/resolve-plugin.ts index 4aa0c9bbb..ff449b225 100644 --- a/src/resolve-plugin.ts +++ b/src/resolve-plugin.ts @@ -15,7 +15,7 @@ const resolvePackage = (id: string, options: ResolveOpts): Promise => const PACKAGE_NAME_RE = /^[@a-z]/ -export const resolvePlugin = (): Plugin => { +export const resolvePlugin = ({ bundle }: { bundle?: boolean }): Plugin => { return { name: 'resolve', @@ -25,11 +25,14 @@ export const resolvePlugin = (): Plugin => { return false } - const cwd = importer && dirname(importer) - if (cwd && PACKAGE_NAME_RE.test(source)) { - const id = await resolvePackage(source, { basedir: cwd }) - return id + if (bundle) { + const cwd = importer && dirname(importer) + if (cwd && PACKAGE_NAME_RE.test(source)) { + const id = await resolvePackage(source, { basedir: cwd }) + return id + } } + return null }, }