Skip to content

Commit d14d4e6

Browse files
elevatebartyyx990803
authored andcommitted
fix: allow relative baseUrl other than ./ (vuejs#2168)
1 parent 4a035e2 commit d14d4e6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/@vue/cli-service/__tests__/Service.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ test('handle option baseUrl and outputDir correctly', () => {
9494
expect(service.projectOptions.outputDir).toBe('/public')
9595
})
9696

97+
test('normalize baseUrl when relative', () => {
98+
mockPkg({
99+
vue: {
100+
baseUrl: './foo/bar'
101+
}
102+
})
103+
const service = createMockService()
104+
expect(service.projectOptions.baseUrl).toBe('foo/bar/')
105+
})
106+
107+
test('keep baseUrl when empty', () => {
108+
mockPkg({
109+
vue: {
110+
baseUrl: ''
111+
}
112+
})
113+
const service = createMockService()
114+
expect(service.projectOptions.baseUrl).toBe('')
115+
})
116+
97117
test('load project options from vue.config.js', () => {
98118
process.env.VUE_CLI_SERVICE_CONFIG_PATH = `/vue.config.js`
99119
fs.writeFileSync('/vue.config.js', `module.exports = { lintOnSave: false }`)

packages/@vue/cli-service/lib/Service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ module.exports = class Service {
298298
}
299299

300300
// normalize some options
301+
ensureSlash(resolved, 'baseUrl')
301302
if (typeof resolved.baseUrl === 'string') {
302303
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
303304
}
304-
ensureSlash(resolved, 'baseUrl')
305305
removeSlash(resolved, 'outputDir')
306306

307307
// deprecation warning

0 commit comments

Comments
 (0)