Skip to content

Commit d46aeb6

Browse files
committedApr 6, 2019
fix: no longer use .mjs for esm bundle
1 parent 486d744 commit d46aeb6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎src/index.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ export class Bundler {
8585
this.pkg.data = {}
8686
}
8787

88+
if (/\.mjs$/.test(this.pkg.data.module || this.pkg.data.main)) {
89+
logger.warn(
90+
`Bili no longer use .mjs extension for esm bundle, you should use .js instead!`
91+
)
92+
}
93+
8894
const userConfig =
8995
options.configFile === false
9096
? {}
@@ -411,7 +417,10 @@ export class Bundler {
411417
: getFileName
412418
const fileName = fileNameTemplate
413419
.replace(/\[min\]/, minPlaceholder)
414-
.replace(/\[ext\]/, /^esm?$/.test(rollupFormat) ? '.mjs' : '.js')
420+
// The `[ext]` placeholder no longer makes sense
421+
// Since we only output to `.js` now
422+
// Probably remove it in the future
423+
.replace(/\[ext\]/, '.js')
415424

416425
return {
417426
inputConfig: {
@@ -678,10 +687,7 @@ async function printAssets(assets: Assets, title: string) {
678687
}
679688

680689
function getDefaultFileName(format: RollupFormat) {
681-
const isESM = /^esm?$/.test(format)
682-
return format === 'cjs' || isESM
683-
? `[name][min][ext]`
684-
: `[name].[format][min][ext]`
690+
return format === 'cjs' ? `[name][min][ext]` : `[name].[format][min][ext]`
685691
}
686692

687693
export { Config, NormalizedConfig, Options, ConfigOutput }

‎src/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ export interface ConfigOutput {
131131
* Placeholders:
132132
* - `[name]`: The base name of input file. (without extension)
133133
* - `[format]`: The output format. (without `-min` suffix)
134-
* - `[ext]`: The extension. It's `.mjs` for `esm` format, `.js` otherwise
135134
* - `[min]`: It will replaced by `.min` when the format ends with `-min`, otherwise it's an empty string.
136135
*
137136
* The value can also be a function which returns the fileName template,

0 commit comments

Comments
 (0)
Please sign in to comment.