Skip to content

Commit

Permalink
Fix: Bundle format and minification in build command
Browse files Browse the repository at this point in the history
  • Loading branch information
1aron committed Feb 21, 2024
1 parent 9c21732 commit a49c379
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions packages/techor/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ export default async function build() {
} else {
entries = normalize(entries)
}
let isGlobalFile: boolean
let forceBundle: boolean
const extendedBuild = extend(config.build, { output: rollupOutputOptions }) as BuildOutputOptions
// single entry
if (extendedBuild.output.file) {
if (!extendedBuild.output.format) {
extendedBuild.output.format = config.build.formatOfExt[extname(extendedBuild.output.file)]
}
const fileBasenameSplits = basename(extendedBuild.output.file).split('.')
if (fileBasenameSplits.includes('min')) extendedBuild.minify = true
isGlobalFile = fileBasenameSplits.includes('global')
if (isGlobalFile || fileBasenameSplits.includes('iife')) extendedBuild.output.format = 'iife'
if (fileBasenameSplits.includes('min')) {
forceBundle = true
extendedBuild.minify = true
}
if (fileBasenameSplits.includes('global') || fileBasenameSplits.includes('iife')) extendedBuild.output.format = 'iife'
for (const [eachInput, eachBuildOptions] of buildMap) {
for (const eachOutputOptions of eachBuildOptions.outputOptionsList) {
if (normalize(eachOutputOptions.output.file) === normalize(extendedBuild.output.file)) {
Expand Down Expand Up @@ -134,7 +136,7 @@ export default async function build() {
}
} as RollupInputOptions, config.build.input)
buildOptions.input.input = entries
buildOptions.input.external = (config.build.input.external && !isGlobalFile) && getWideExternal(config.build.input.external);
buildOptions.input.external = (config.build.input.external && !forceBundle) && getWideExternal(config.build.input.external);
(buildOptions.input.plugins as RollupInputPluginOption[]).unshift(
...[
(config.build.swc || extendedBuild.minify) && swc({ ...config.build.swc, minify: extendedBuild.minify }),
Expand Down
4 changes: 2 additions & 2 deletions packages/techor/tests/global/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ beforeAll(() => {
})

it('generate iife format', () => {
expect(readFileSync(join(__dirname, './dist/global.js'), 'utf-8')).toContain('(function () {')
expect(readFileSync(join(__dirname, './dist/global.js'), 'utf-8')).toContain('(function (isObject)')
})

it('should bundle all deps', () => {
expect(readFileSync(join(__dirname, './dist/global.js'), 'utf-8')).toContain('function isObject(value)')
expect(readFileSync(join(__dirname, './dist/global.min.js'), 'utf-8')).toContain('function isObject(value)')
})

it('should be minifined', () => {
Expand Down

0 comments on commit a49c379

Please sign in to comment.