mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-25 08:38:57 -06:00
feat: allow using relative baseUrl
This commit is contained in:
@@ -248,6 +248,7 @@ module.exports = class Service {
|
||||
}
|
||||
|
||||
// normlaize some options
|
||||
resolved.baseUrl = resolved.baseUrl.replace(/^\.\//, '')
|
||||
ensureSlash(resolved, 'baseUrl')
|
||||
removeSlash(resolved, 'outputDir')
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user