Skip to content

Commit abb82ab

Browse files
javoskiyyx990803
authored andcommittedApr 26, 2018
fix(cli-service): should not add a leading slash to baseUrl when it is absolute (#1172)
fix #1084
1 parent 79bc088 commit abb82ab

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed
 

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

+12
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ test('load project options from package.json', () => {
5252
expect(service.projectOptions.lintOnSave).toBe(true)
5353
})
5454

55+
test('handle option baseUrl and outputDir correctly', () => {
56+
mockPkg({
57+
vue: {
58+
baseUrl: 'https://foo.com/bar',
59+
outputDir: '/public/'
60+
}
61+
})
62+
const service = createMockService()
63+
expect(service.projectOptions.baseUrl).toBe('https://foo.com/bar/')
64+
expect(service.projectOptions.outputDir).toBe('public')
65+
})
66+
5567
test('load project options from vue.config.js', () => {
5668
process.env.VUE_CLI_SERVICE_CONFIG_PATH = `/vue.config.js`
5769
fs.writeFileSync('/vue.config.js', `module.exports = { lintOnSave: false }`)

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@ module.exports = class Service {
222222
}
223223

224224
function ensureSlash (config, key) {
225-
if (typeof config[key] === 'string') {
226-
config[key] = config[key]
227-
.replace(/^([^/.])/, '/$1')
228-
.replace(/([^/])$/, '$1/')
225+
let val = config[key]
226+
if (typeof val === 'string') {
227+
if (!/^https?:/.test(val)) {
228+
val = val.replace(/^([^/.])/, '/$1')
229+
}
230+
config[key] = val.replace(/([^/])$/, '$1/')
229231
}
230232
}
231233

0 commit comments

Comments
 (0)
Please sign in to comment.