mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
fix(lib)!: remove format prefixes for cjs and esm (#8107)
This commit is contained in:
parent
c32e3ac502
commit
ad8c3b1c77
@ -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)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -596,6 +596,10 @@ export function resolveLibFilename(
|
||||
extension = format === 'es' ? 'mjs' : 'js'
|
||||
}
|
||||
|
||||
if (format === 'cjs' || format === 'es') {
|
||||
return `${name}.${extension}`
|
||||
}
|
||||
|
||||
return `${name}.${format}.${extension}`
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<div class="dynamic-import-message"></div>
|
||||
|
||||
<script type="module">
|
||||
import myLib from './my-lib-custom-filename.es.mjs'
|
||||
import myLib from './my-lib-custom-filename.mjs'
|
||||
|
||||
myLib('.es')
|
||||
</script>
|
||||
|
@ -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'
|
||||
)
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
/* eslint-disable node/no-missing-import */
|
||||
// @ts-ignore
|
||||
import { CompA } from '../dist/lib/my-vue-lib.es'
|
||||
import '../dist/lib/style.css'
|
||||
import { createApp } from 'vue'
|
||||
// @ts-ignore
|
||||
import { CompA } from '../dist/lib/my-vue-lib'
|
||||
import '../dist/lib/style.css'
|
||||
|
||||
const app = createApp(CompA)
|
||||
app.mount('#app')
|
||||
|
Loading…
Reference in New Issue
Block a user