diff --git a/packages/techor/src/commands/build.ts b/packages/techor/src/commands/build.ts index ce6c559..2b91383 100644 --- a/packages/techor/src/commands/build.ts +++ b/packages/techor/src/commands/build.ts @@ -85,7 +85,7 @@ 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) { @@ -93,9 +93,11 @@ export default async function build() { 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)) { @@ -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 }), diff --git a/packages/techor/tests/global/test.ts b/packages/techor/tests/global/test.ts index dab1197..ee44d44 100644 --- a/packages/techor/tests/global/test.ts +++ b/packages/techor/tests/global/test.ts @@ -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', () => {