@@ -32,7 +32,8 @@ import {
32
32
Format ,
33
33
ConfigEntryObject ,
34
34
Env ,
35
- ConfigOutput
35
+ ConfigOutput ,
36
+ FileNameContext
36
37
} from './types'
37
38
38
39
// Make rollup-plugin-vue use basename in component.__file instead of absolute path
@@ -197,7 +198,9 @@ export class Bundler {
197
198
198
199
// UMD format should always bundle node_modules
199
200
const bundleNodeModules =
200
- format === 'umd' || format === 'iife' || config . bundleNodeModules
201
+ rollupFormat === 'umd' ||
202
+ rollupFormat === 'iife' ||
203
+ config . bundleNodeModules
201
204
202
205
plugins . push (
203
206
nodeResolvePlugin ( {
@@ -384,15 +387,14 @@ export class Bundler {
384
387
}
385
388
} )
386
389
387
- const isESM = / ^ e s m ? $ / . test ( format )
388
-
389
- const fileName =
390
- config . output . fileName ||
391
- ( format === 'cjs' || isESM
392
- ? `[name][min][ext]`
393
- : `[name].[format][min][ext]` )
394
-
395
- const extPlaceholder = isESM ? '.mjs' : '.js'
390
+ const getFileName = config . output . fileName || defaultGetFileName
391
+ const fileNameTemplate =
392
+ typeof getFileName === 'function'
393
+ ? getFileName ( { format : rollupFormat , minify } )
394
+ : getFileName
395
+ const fileName = fileNameTemplate
396
+ . replace ( / \[ m i n \] / , minPlaceholder )
397
+ . replace ( / \[ e x t \] / , / ^ e s m ? $ / . test ( rollupFormat ) ? '.mjs' : '.js' )
396
398
397
399
return {
398
400
inputConfig : {
@@ -424,9 +426,7 @@ export class Bundler {
424
426
globals : config . globals ,
425
427
format : rollupFormat ,
426
428
dir : path . resolve ( config . output . dir || 'dist' ) ,
427
- entryFileNames : fileName
428
- . replace ( / \[ m i n \] / , minPlaceholder )
429
- . replace ( / \[ e x t \] / , extPlaceholder ) ,
429
+ entryFileNames : fileName ,
430
430
name : config . output . moduleName ,
431
431
banner,
432
432
sourcemap :
@@ -654,4 +654,11 @@ async function printAssets(assets: Assets, title: string) {
654
654
)
655
655
}
656
656
657
+ function defaultGetFileName ( { format } : FileNameContext ) {
658
+ const isESM = / ^ e s m ? $ / . test ( format )
659
+ return format === 'cjs' || isESM
660
+ ? `[name][min][ext]`
661
+ : `[name].[format][min][ext]`
662
+ }
663
+
657
664
export { Config , NormalizedConfig , Options , ConfigOutput }
0 commit comments