Skip to content

Commit 5eed44d

Browse files
committedJan 29, 2019
fix: use fileName option from config
1 parent 9690fc7 commit 5eed44d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed
 

‎src/index.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,15 @@ export class Bundler {
365365
}
366366
})
367367

368+
const isESM = /^esm?$/.test(format)
369+
368370
const fileName =
369-
format === 'cjs'
370-
? `[name][min].js`
371-
: format === 'esm'
372-
? `[name][min].mjs`
373-
: `[name].[format][min].js`
371+
config.output.fileName ||
372+
(format === 'cjs' || isESM
373+
? `[name][min][ext]`
374+
: `[name].[format][min][ext]`)
375+
376+
const extPlaceholder = isESM ? '.mjs' : '.js'
374377

375378
return {
376379
inputConfig: {
@@ -402,7 +405,9 @@ export class Bundler {
402405
globals: config.globals,
403406
format: rollupFormat,
404407
dir: path.resolve(config.output.dir || 'dist'),
405-
entryFileNames: fileName.replace(/\[min\]/, minPlaceholder),
408+
entryFileNames: fileName
409+
.replace(/\[min\]/, minPlaceholder)
410+
.replace(/\[ext\]/, extPlaceholder),
406411
name: config.output.moduleName,
407412
banner
408413
}

‎src/types.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Banner } from './utils/get-banner'
55
export type Format =
66
| RollupFormat
77
| 'cjs-min'
8+
| 'es-min'
89
| 'esm-min'
910
| 'umd-min'
1011
| 'iife-min'
@@ -79,13 +80,13 @@ export interface ConfigOutput {
7980
* Output file name
8081
*
8182
* Default value:
82-
* - `[name][min].js` in `cjs` format
83-
* - `[name][min].mjs` in `esm` format
84-
* - `[name][min].[format].js` in `umd` and `iife` formats.
83+
* - `[name][min][ext]` in `cjs` and `esm` format.
84+
* - `[name][min].[format].js` in other formats.
8585
*
8686
* Placeholders:
8787
* - `[name]`: The base name of input file. (without extension)
8888
* - `[format]`: The output format. (without `-min` suffix)
89+
* - `[ext]`: The extension. It's `.mjs` for `esm` format, `.js` otherwise
8990
* - `[min]`: It will replaced by `.min` when the format ends with `-min`, otherwise it's an empty string.
9091
* @cli `--file-name <fileName>`
9192
*/

0 commit comments

Comments
 (0)
Please sign in to comment.