Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not introduce extra level of directory when building lib for scoped packages #4320

Merged
merged 2 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/@vue/cli-service/__tests__/buildLib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down