Skip to content

Commit

Permalink
feat: add --bundle flag
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 10, 2020
1 parent f924424 commit f6a4ed1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cli
.option('--target <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')
Expand All @@ -28,7 +29,7 @@ cli
input: files,
plugins: [
hashbangPlugin(),
resolvePlugin(),
resolvePlugin({ bundle: options.bundle }),
commonjsPlugin(),
esbuildPlugin({ minify: options.minify, target: options.target }),
],
Expand Down
13 changes: 8 additions & 5 deletions src/resolve-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const resolvePackage = (id: string, options: ResolveOpts): Promise<string> =>

const PACKAGE_NAME_RE = /^[@a-z]/

export const resolvePlugin = (): Plugin => {
export const resolvePlugin = ({ bundle }: { bundle?: boolean }): Plugin => {
return {
name: 'resolve',

Expand All @@ -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
},
}
Expand Down

0 comments on commit f6a4ed1

Please sign in to comment.