Skip to content

Commit b41ed76

Browse files
authored
fix: mini-css-extract-plugin publicPath option can be an absolute path (#6230)
When the user sets the project public path to the absolute path, the extract-css publicPath option should be changed accordingly
1 parent f8017ca commit b41ed76

File tree

1 file changed

+10
-6
lines changed
  • packages/@vue/cli-service/lib/config

1 file changed

+10
-6
lines changed

packages/@vue/cli-service/lib/config/css.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs')
22
const path = require('path')
3+
const isAbsoluteUrl = require('../util/isAbsoluteUrl')
34

45
const findExisting = (context, files) => {
56
for (const file of files) {
@@ -39,16 +40,19 @@ module.exports = (api, rootOptions) => {
3940
chunkFilename: filename
4041
}, extract && typeof extract === 'object' ? extract : {})
4142

43+
// when project publicPath is a relative path
4244
// use relative publicPath in extracted CSS based on extract location
43-
const cssPublicPath = process.env.VUE_CLI_BUILD_TARGET === 'lib'
44-
// in lib mode, CSS is extracted to dist root.
45-
? './'
46-
: '../'.repeat(
47-
extractOptions.filename
45+
const cssPublicPath = (isAbsoluteUrl(rootOptions.publicPath) || rootOptions.publicPath.startsWith('/'))
46+
? rootOptions.publicPath
47+
: process.env.VUE_CLI_BUILD_TARGET === 'lib'
48+
// in lib mode, CSS is extracted to dist root.
49+
? './'
50+
: '../'.repeat(
51+
extractOptions.filename
4852
.replace(/^\.[/\\]/, '')
4953
.split(/[/\\]/g)
5054
.length - 1
51-
)
55+
)
5256

5357
// check if the project has a valid postcss config
5458
// if it doesn't, don't use postcss-loader for direct style imports

0 commit comments

Comments
 (0)