diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts index 3b34851203e149..97d823ff648dc7 100644 --- a/packages/vite/src/node/__tests__/build.spec.ts +++ b/packages/vite/src/node/__tests__/build.spec.ts @@ -33,7 +33,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/name') ) - expect(filename).toBe('custom-filename.es.mjs') + expect(filename).toBe('custom-filename.mjs') }) test('package name as filename', () => { @@ -45,7 +45,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/name') ) - expect(filename).toBe('mylib.es.mjs') + expect(filename).toBe('mylib.mjs') }) test('custom filename and no package name', () => { @@ -58,7 +58,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/noname') ) - expect(filename).toBe('custom-filename.es.mjs') + expect(filename).toBe('custom-filename.mjs') }) test('missing filename', () => { @@ -75,9 +75,9 @@ describe('resolveLibFilename', () => { test('commonjs package extensions', () => { const formatsToFilenames: FormatsToFileNames = [ - ['es', 'my-lib.es.mjs'], + ['es', 'my-lib.mjs'], ['umd', 'my-lib.umd.js'], - ['cjs', 'my-lib.cjs.js'], + ['cjs', 'my-lib.js'], ['iife', 'my-lib.iife.js'] ] @@ -94,9 +94,9 @@ describe('resolveLibFilename', () => { test('module package extensions', () => { const formatsToFilenames: FormatsToFileNames = [ - ['es', 'my-lib.es.js'], + ['es', 'my-lib.js'], ['umd', 'my-lib.umd.cjs'], - ['cjs', 'my-lib.cjs.cjs'], + ['cjs', 'my-lib.cjs'], ['iife', 'my-lib.iife.js'] ] @@ -107,7 +107,7 @@ describe('resolveLibFilename', () => { resolve(__dirname, 'packages/module') ) - expect(filename).toBe(expectedFilename) + expect(expectedFilename).toBe(filename) } }) }) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index 73db49c1c2b7ae..155735b0b4217a 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -592,6 +592,10 @@ export function resolveLibFilename( extension = format === 'es' ? 'mjs' : 'js' } + if (format === 'cjs' || format === 'es') { + return `${name}.${extension}` + } + return `${name}.${format}.${extension}` } diff --git a/playground/lib/index.dist.html b/playground/lib/index.dist.html index 9e0fac1f6b5730..02362a9c111e5e 100644 --- a/playground/lib/index.dist.html +++ b/playground/lib/index.dist.html @@ -5,7 +5,7 @@
diff --git a/playground/resolve-config/__tests__/resolve-config.spec.ts b/playground/resolve-config/__tests__/resolve-config.spec.ts index 9b3588cafcc47d..1646855129b780 100644 --- a/playground/resolve-config/__tests__/resolve-config.spec.ts +++ b/playground/resolve-config/__tests__/resolve-config.spec.ts @@ -11,7 +11,7 @@ const build = (configName: string) => { const getDistFile = (configName: string, extension: string) => { return fs.readFileSync( - fromTestDir(`${configName}/dist/index.es.${extension}`), + fromTestDir(`${configName}/dist/index.${extension}`), 'utf8' ) } diff --git a/playground/vue-lib/src-consumer/index.ts b/playground/vue-lib/src-consumer/index.ts index ee20f81d75a7ca..880acf90238edf 100644 --- a/playground/vue-lib/src-consumer/index.ts +++ b/playground/vue-lib/src-consumer/index.ts @@ -1,8 +1,7 @@ -/* eslint-disable node/no-missing-import */ +import { createApp } from 'vue' // @ts-ignore -import { CompA } from '../dist/lib/my-vue-lib.es' +import { CompA } from '../dist/lib/my-vue-lib' import '../dist/lib/style.css' -import { createApp } from 'vue' const app = createApp(CompA) app.mount('#app')