From 85250e38e39b853c58d8808c37995f001157bfdd Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 3 Aug 2022 19:51:12 +0800 Subject: [PATCH] fix: webpack5 static file path --- .../vue-cli-plugin-uni/lib/chain-webpack.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/vue-cli-plugin-uni/lib/chain-webpack.js b/packages/vue-cli-plugin-uni/lib/chain-webpack.js index bfca41558..ecdb30d16 100644 --- a/packages/vue-cli-plugin-uni/lib/chain-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/chain-webpack.js @@ -33,6 +33,22 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { } }) } + if (newOptions.fallback && newOptions.fallback.options) { + const generator = {} + const oldOptions = newOptions.fallback.options + const keys = ['publicPath', 'outputPath'] + keys.forEach(key => { + generator[key] = pathData => { + const outputPath = oldOptions.outputPath(null, pathData.module.request) + const basename = path.basename(outputPath) + return outputPath.substring(0, outputPath.length - basename.length) + } + }) + generator.filename = pathData => { + return path.basename(pathData.module.request) + } + webpackConfig.module.rule(staticType).set('generator', generator) + } } else { webpackConfig.module .rule(staticType) @@ -68,6 +84,18 @@ module.exports = function chainWebpack (platformOptions, vueOptions, api) { )) .before('css-loader') } + if (webpack.version[0] > 4) { + langRule.oneOf(type) + .use('css-loader') + .tap(options => { + options.url = { + filter: function (url) { + return url[0] !== '/' + } + } + return options + }) + } langRule.oneOf(type) .use('uniapp-preprocss') .loader(resolve('packages/webpack-preprocess-loader')) -- GitLab