File tree 5 files changed +22
-6
lines changed
packages/@vue/cli-service/lib
5 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,7 @@ module.exports = class Service {
248
248
}
249
249
250
250
// normlaize some options
251
+ resolved . baseUrl = resolved . baseUrl . replace ( / ^ \. \/ / , '' )
251
252
ensureSlash ( resolved , 'baseUrl' )
252
253
removeSlash ( resolved , 'outputDir' )
253
254
Original file line number Diff line number Diff line change @@ -24,9 +24,14 @@ module.exports = (api, options) => {
24
24
const shadowMode = ! ! process . env . VUE_CLI_CSS_SHADOW_MODE
25
25
const isProd = process . env . NODE_ENV === 'production'
26
26
const shouldExtract = isProd && extract !== false && ! shadowMode
27
+ const filename = getAssetPath (
28
+ options ,
29
+ `css/[name].[contenthash:8].css` ,
30
+ true /* placeAtRootIfRelative */
31
+ )
27
32
const extractOptions = Object . assign ( {
28
- filename : getAssetPath ( options , `css/[name].[contenthash:8].css` ) ,
29
- chunkFilename : getAssetPath ( options , 'css/[name].[contenthash:8].css' )
33
+ filename,
34
+ chunkFilename : filename
30
35
} , extract && typeof extract === 'object' ? extract : { } )
31
36
32
37
// check if the project has a valid postcss config
Original file line number Diff line number Diff line change @@ -2,13 +2,18 @@ module.exports = (api, options) => {
2
2
api . chainWebpack ( webpackConfig => {
3
3
if ( process . env . NODE_ENV === 'production' ) {
4
4
const getAssetPath = require ( '../util/getAssetPath' )
5
+ const filename = getAssetPath (
6
+ options ,
7
+ `js/[name].[chunkhash:8].js` ,
8
+ true /* placeAtRootIfRelative */
9
+ )
5
10
6
11
webpackConfig
7
12
. mode ( 'production' )
8
13
. devtool ( 'source-map' )
9
14
. output
10
- . filename ( getAssetPath ( options , `js/[name].[chunkhash:8].js` ) )
11
- . chunkFilename ( getAssetPath ( options , `js/[name].[chunkhash:8].js` ) )
15
+ . filename ( filename )
16
+ . chunkFilename ( filename )
12
17
13
18
// keep module.id stable when vendor modules does not change
14
19
webpackConfig
Original file line number Diff line number Diff line change 1
1
const { createSchema, validate } = require ( '@vue/cli-shared-utils' )
2
2
3
3
const schema = createSchema ( joi => joi . object ( {
4
- baseUrl : joi . string ( ) ,
4
+ baseUrl : joi . string ( ) . allow ( '' ) ,
5
5
outputDir : joi . string ( ) ,
6
6
assetsDir : joi . string ( ) ,
7
7
runtimeCompiler : joi . boolean ( ) ,
Original file line number Diff line number Diff line change 1
1
const path = require ( 'path' )
2
2
3
- module . exports = function getAssetPath ( options , filePath ) {
3
+ module . exports = function getAssetPath ( options , filePath , placeAtRootIfRelative ) {
4
+ // if the user is using a relative URL, place js & css at dist root to ensure
5
+ // relative paths work properly
6
+ if ( placeAtRootIfRelative && options . baseUrl . charAt ( 0 ) !== '/' ) {
7
+ return filePath . replace ( / ^ \w + \/ / , '' )
8
+ }
4
9
return options . assetsDir
5
10
? path . posix . join ( options . assetsDir , filePath )
6
11
: filePath
You can’t perform that action at this time.
0 commit comments