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(cli-service): should not add a leading slash to baseUrl when it is absolute #1172

Merged
merged 2 commits into from
Apr 26, 2018
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
12 changes: 12 additions & 0 deletions packages/@vue/cli-service/__tests__/Service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ test('load project options from package.json', () => {
expect(service.projectOptions.lintOnSave).toBe(true)
})

test('handle option baseUrl and outputDir correctly', () => {
mockPkg({
vue: {
baseUrl: 'https://foo.com/bar',
outputDir: '/public/'
}
})
const service = createMockService()
expect(service.projectOptions.baseUrl).toBe('https://foo.com/bar/')
expect(service.projectOptions.outputDir).toBe('public')
})

test('load project options from vue.config.js', () => {
process.env.VUE_CLI_SERVICE_CONFIG_PATH = `/vue.config.js`
fs.writeFileSync('/vue.config.js', `module.exports = { lintOnSave: false }`)
Expand Down
10 changes: 6 additions & 4 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ module.exports = class Service {
}

function ensureSlash (config, key) {
if (typeof config[key] === 'string') {
config[key] = config[key]
.replace(/^([^/.])/, '/$1')
.replace(/([^/])$/, '$1/')
let val = config[key]
if (typeof val === 'string') {
if (!/^https?:/.test(val)) {
val = val.replace(/^([^/.])/, '/$1')
}
config[key] = val.replace(/([^/])$/, '$1/')
}
}

Expand Down