From f6a4ed1ad5131af0916361453effd2ace84cd470 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Sun, 10 May 2020 14:04:28 +0800 Subject: [PATCH] feat: add --bundle flag --- src/cli.ts | 3 ++- src/resolve-plugin.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) 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 }, }