feat: allow using relative baseUrl

This commit is contained in:
Evan You
2018-06-05 00:22:20 -04:00
parent bfebc6d934
commit dc382111d9
5 changed files with 22 additions and 6 deletions

View File

@@ -248,6 +248,7 @@ module.exports = class Service {
}
// normlaize some options
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
ensureSlash(resolved, 'baseUrl')
removeSlash(resolved, 'outputDir')

View File

@@ -24,9 +24,14 @@ module.exports = (api, options) => {
const shadowMode = !!process.env.VUE_CLI_CSS_SHADOW_MODE
const isProd = process.env.NODE_ENV === 'production'
const shouldExtract = isProd && extract !== false && !shadowMode
const filename = getAssetPath(
options,
`css/[name].[contenthash:8].css`,
true /* placeAtRootIfRelative */
)
const extractOptions = Object.assign({
filename: getAssetPath(options, `css/[name].[contenthash:8].css`),
chunkFilename: getAssetPath(options, 'css/[name].[contenthash:8].css')
filename,
chunkFilename: filename
}, extract && typeof extract === 'object' ? extract : {})
// check if the project has a valid postcss config

View File

@@ -2,13 +2,18 @@ module.exports = (api, options) => {
api.chainWebpack(webpackConfig => {
if (process.env.NODE_ENV === 'production') {
const getAssetPath = require('../util/getAssetPath')
const filename = getAssetPath(
options,
`js/[name].[chunkhash:8].js`,
true /* placeAtRootIfRelative */
)
webpackConfig
.mode('production')
.devtool('source-map')
.output
.filename(getAssetPath(options, `js/[name].[chunkhash:8].js`))
.chunkFilename(getAssetPath(options, `js/[name].[chunkhash:8].js`))
.filename(filename)
.chunkFilename(filename)
// keep module.id stable when vendor modules does not change
webpackConfig

View File

@@ -1,7 +1,7 @@
const { createSchema, validate } = require('@vue/cli-shared-utils')
const schema = createSchema(joi => joi.object({
baseUrl: joi.string(),
baseUrl: joi.string().allow(''),
outputDir: joi.string(),
assetsDir: joi.string(),
runtimeCompiler: joi.boolean(),

View File

@@ -1,6 +1,11 @@
const path = require('path')
module.exports = function getAssetPath (options, filePath) {
module.exports = function getAssetPath (options, filePath, placeAtRootIfRelative) {
// if the user is using a relative URL, place js & css at dist root to ensure
// relative paths work properly
if (placeAtRootIfRelative && options.baseUrl.charAt(0) !== '/') {
return filePath.replace(/^\w+\//, '')
}
return options.assetsDir
? path.posix.join(options.assetsDir, filePath)
: filePath