mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-22 12:28:44 -05:00
fix: do not introduce extra level of directory when building lib for scope packages (#4320)
This fixes references to static assets in the bundled script. Fixes #4311
This commit is contained in:
committed by
Haoqun Jiang
parent
e2e3469a18
commit
de9748a5a5
@@ -174,3 +174,43 @@ test('build as lib with --filename option', async () => {
|
||||
return window.testLib.bar
|
||||
})).toBe(2)
|
||||
})
|
||||
|
||||
test('build as lib without --name and --filename options (default to package name)', async () => {
|
||||
const project = await create('build-lib-no-name-and-filename-option', defaultPreset)
|
||||
await project.write('package.json', `
|
||||
{
|
||||
"name": "test-lib"
|
||||
}
|
||||
`)
|
||||
await project.write('src/main.js', `
|
||||
export default { foo: 1 }
|
||||
export const bar = 2
|
||||
`)
|
||||
const { stdout } = await project.run('vue-cli-service build --target lib src/main.js')
|
||||
expect(stdout).toMatch('Build complete.')
|
||||
|
||||
expect(project.has('dist/demo.html')).toBe(true)
|
||||
expect(project.has('dist/test-lib.common.js')).toBe(true)
|
||||
expect(project.has('dist/test-lib.umd.js')).toBe(true)
|
||||
expect(project.has('dist/test-lib.umd.min.js')).toBe(true)
|
||||
})
|
||||
|
||||
test('build as lib without --name and --filename options (default to package name, minus scope)', async () => {
|
||||
const project = await create('build-lib-no-name-and-filename-option-with-scope', defaultPreset)
|
||||
await project.write('package.json', `
|
||||
{
|
||||
"name": "@foo/test-lib"
|
||||
}
|
||||
`)
|
||||
await project.write('src/main.js', `
|
||||
export default { foo: 1 }
|
||||
export const bar = 2
|
||||
`)
|
||||
const { stdout } = await project.run('vue-cli-service build --target lib src/main.js')
|
||||
expect(stdout).toMatch('Build complete.')
|
||||
|
||||
expect(project.has('dist/demo.html')).toBe(true)
|
||||
expect(project.has('dist/test-lib.common.js')).toBe(true)
|
||||
expect(project.has('dist/test-lib.umd.js')).toBe(true)
|
||||
expect(project.has('dist/test-lib.umd.min.js')).toBe(true)
|
||||
})
|
||||
|
||||
@@ -21,8 +21,11 @@ module.exports = (api, { entry, name, formats, filename }, options) => {
|
||||
const isVueEntry = /\.vue$/.test(entry)
|
||||
const libName = (
|
||||
name ||
|
||||
api.service.pkg.name ||
|
||||
path.basename(entry).replace(/\.(jsx?|vue)$/, '')
|
||||
(
|
||||
api.service.pkg.name
|
||||
? api.service.pkg.name.replace(/^@.+\//, '')
|
||||
: path.basename(entry).replace(/\.(jsx?|vue)$/, '')
|
||||
)
|
||||
)
|
||||
filename = filename || libName
|
||||
function genConfig (format, postfix = format, genHTML) {
|
||||
|
||||
Reference in New Issue
Block a user