From 47ff9d2ec5e96fe990ba510486557d0ccb5d5197 Mon Sep 17 00:00:00 2001 From: Veath Date: Thu, 21 Jan 2021 11:38:26 +0800 Subject: [PATCH] fix: mini-css-extract-plugin publicPath option When the user set the project public path to the absolute path, the extract-css publicPath option should be changed synchronously --- packages/@vue/cli-service/lib/config/css.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/@vue/cli-service/lib/config/css.js b/packages/@vue/cli-service/lib/config/css.js index 8b8d1d82e7..b942cafd61 100644 --- a/packages/@vue/cli-service/lib/config/css.js +++ b/packages/@vue/cli-service/lib/config/css.js @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') +const isAbsoluteUrl = require('../util/isAbsoluteUrl') const findExisting = (context, files) => { for (const file of files) { @@ -39,16 +40,19 @@ module.exports = (api, rootOptions) => { chunkFilename: filename }, extract && typeof extract === 'object' ? extract : {}) + // when project publicPath is a relative path // use relative publicPath in extracted CSS based on extract location - const cssPublicPath = process.env.VUE_CLI_BUILD_TARGET === 'lib' - // in lib mode, CSS is extracted to dist root. - ? './' - : '../'.repeat( - extractOptions.filename + const cssPublicPath = (isAbsoluteUrl(rootOptions.publicPath) || rootOptions.publicPath.startsWith('/')) + ? rootOptions.publicPath + : process.env.VUE_CLI_BUILD_TARGET === 'lib' + // in lib mode, CSS is extracted to dist root. + ? './' + : '../'.repeat( + extractOptions.filename .replace(/^\.[/\\]/, '') .split(/[/\\]/g) .length - 1 - ) + ) // check if the project has a valid postcss config // if it doesn't, don't use postcss-loader for direct style imports