Skip to content

Commit

Permalink
feat: support minifying outputs based on .min.* dist name (#215)
Browse files Browse the repository at this point in the history
 closes #214
  • Loading branch information
antfu authored Jul 15, 2021
1 parent 24efd1f commit 4713443
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/build/rollup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('rollupConfig', () => {
const config = getRollupConfig({}, core)
expect(Array.isArray(config)).toBeTruthy()
expect(typeof config[0].input).toBe('string')
expect(config.length).toBe(2)
expect(config.length).toBe(3)
})
it('should generate builds for binaries', () => {
const config = getRollupConfig({}, cli)
Expand Down
29 changes: 16 additions & 13 deletions src/core/build/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import esbuild, { Options as EsbuildOptions } from 'rollup-plugin-esbuild'
import { Package } from '../package'
import { includeDefinedProperties, includeIf } from '../utils'
import { builtins } from './builtins'
import { convertToUMDName, getNameFunction } from './utils'
import { convertToUMDName, getNameFunction, shouldMinify } from './utils'

const __NODE_ENV__ = process.env.NODE_ENV

Expand Down Expand Up @@ -102,7 +102,7 @@ export function getRollupConfig(
}),
]

const getPlugins = () => [
const getPlugins = (filename: string) => [
aliasPlugin({
entries: alias,
}),
Expand All @@ -119,6 +119,7 @@ export function getRollupConfig(
commonjsPlugin({ include: /node_modules/ }),
esbuild({
target: 'es2018',
minify: shouldMinify(filename),
...esbuildOptions,
}),
jsonPlugin(),
Expand Down Expand Up @@ -162,7 +163,7 @@ export function getRollupConfig(
format: override.format,
} as OutputOptions,
external,
plugins: getPlugins(),
plugins: getPlugins(override.output),
},
]
}
Expand All @@ -182,17 +183,19 @@ export function getRollupConfig(
banner: '#!/usr/bin/env node\n',
} as OutputOptions,
external,
plugins: getPlugins(),
})
),
...includeIf(input, input =>
defu({}, options as RollupOptions, {
input,
output: defaultOutputs,
external,
plugins: getPlugins(),
plugins: getPlugins(binary),
})
),
...(input
? defaultOutputs.map(output =>
defu({}, options as RollupOptions, {
input,
output,
external,
plugins: getPlugins(output.entryFileNames as string),
})
)
: []),
...includeIf(typeEntrypoint, input => ({
input,
output: {
Expand All @@ -215,7 +218,7 @@ export function getRollupConfig(
exports: 'auto',
} as OutputOptions,
external,
plugins: getPlugins(),
plugins: getPlugins(outfile),
})
),
...exports
Expand Down
4 changes: 4 additions & 0 deletions src/core/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const formatForName = (
return defaultFormat
}

export const shouldMinify = (filename: string) => {
return !!filename.match(/\.min\.\w+$/)
}

export const convertToUMDName = (name: string) => {
const unnamspacedName = name.split('/').pop()

Expand Down

0 comments on commit 4713443

Please sign in to comment.