Skip to content

Commit

Permalink
fix: don't bundle dts by default
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed May 18, 2020
1 parent c398839 commit edcce14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
29 changes: 11 additions & 18 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,28 @@ cli
})
.option('--bundle', 'Bundle node_modules')
.option('--dts', 'Generate declaration file')
.option('--dts-bundle', 'Bundle types from node_modules')
.option('--watch', 'Watch mode')
.option('--define.* <value>', 'Define compile-time constants')
.option('--external <name>', 'Mark specific packages as external (use with --bundle)')
.option(
'--external <name>',
'Mark specific packages as external (use with --bundle)'
)
.option('--module-name <name>', 'Module name (with with --format umd)')
.option('--jsxFactory <jsxFactory>', 'Name of JSX factory function', {
default: 'React.createElement',
})
.option('--jsxFragment <jsxFragment>', 'Name of JSX fragment function', {
default: 'React.Fragment',
})
.option('--inlineDynamicImports', 'Create a single bundle that inlines dynamic imports')
.option(
'--inlineDynamicImports',
'Create a single bundle that inlines dynamic imports'
)
.action(async (files: string[], options) => {
const { rollup, watch } = await import('rollup')
const { createRollupConfigs, printSizes } = await import('./')
const rollupConfigs = await createRollupConfigs(files, {
watch: options.watch,
minify: options.minify,
jsxFragment: options.jsxFragment,
jsxFactory: options.jsxFactory,
format: options.format,
target: options.target,
dts: options.dts,
bundle: options.bundle,
outDir: options.outDir,
define: options.define,
external: options.external,
moduleName: options.moduleName,
inlineDynamicImports: options.inlineDynamicImports
})
const rollupConfigs = await createRollupConfigs(files, options)
if (options.watch) {
const watcher = watch(
rollupConfigs.map((config) => ({
Expand Down Expand Up @@ -90,7 +83,7 @@ cli
define: options.define,
outDir: 'dist',
format: 'cjs',
target: 'es2017'
target: 'es2017',
})
const bundle = await rollup(rollupConfig.inputConfig)
const { output } = await bundle.write(rollupConfig.outputConfig)
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import { resolvePlugin } from './resolve-plugin'
import { isExternal } from './utils'

type Options = {
// Bundle packages in node_modules
bundle?: boolean
// Generate .d.ts file
dts?: boolean
// Bundle .d.ts files in node_modules
dtsBundle?: boolean
target?: EsbuildTarget
watch?: boolean
minify?: boolean
Expand Down Expand Up @@ -69,7 +73,7 @@ export async function createRollupConfigs(files: string[], options: Options) {
resolvePlugin({
bundle: options.bundle,
external: options.external,
dts,
dtsBundle: options.dtsBundle,
}),
!dts &&
commonjsPlugin({
Expand Down
10 changes: 5 additions & 5 deletions src/resolve-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ const joycon = new JoyCon()
export const resolvePlugin = ({
bundle,
external,
dts,
dtsBundle,
}: {
bundle?: boolean
external?: string[]
dts?: boolean
dtsBundle?: boolean
}): Plugin => {
const nodeResolve = nodeResolvePlugin({
mainFields: dts ? ['types', 'typings'] : ['module', 'main'],
extensions: dts ? ['.d.ts'] : ['.mjs', '.js', '.json', '.node'],
mainFields: dtsBundle ? ['types', 'typings'] : ['module', 'main'],
extensions: dtsBundle ? ['.d.ts'] : ['.mjs', '.js', '.json', '.node'],
customResolveOptions: {
moduleDirectory: dts
moduleDirectory: dtsBundle
? ['node_modules/@types', 'node_modules']
: 'node_modules',
},
Expand Down

0 comments on commit edcce14

Please sign in to comment.