From 460d112e82b0f3ff8d2b25705932bc6f37eadaef Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Mon, 25 Nov 2019 21:40:25 +0800 Subject: [PATCH] fix(v3): url-loader --- .../vue-cli-plugin-uni/lib/app-plus/index.js | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js index fb5bc4355..72da53a43 100644 --- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js +++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js @@ -3,6 +3,7 @@ const webpack = require('webpack') const { getMainEntry, + isInHBuilderX, getPlatformCompiler } = require('@dcloudio/uni-cli-shared') @@ -144,16 +145,23 @@ const v3 = { const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service'] const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view'] + const fileLoaderOptions = isInHBuilderX ? { + emitFile: isAppView, + name: '[path][name].[ext]', + context: process.env.UNI_INPUT_DIR + } : { + emitFile: isAppView, + outputPath (url, resourcePath, context) { + return path.relative(process.env.UNI_INPUT_DIR, resourcePath) + } + } + // 处理静态资源 webpackConfig.module .rule('svg') .use('file-loader') - .options({ - emitFile: isAppView, - outputPath (url, resourcePath, context) { - return path.relative(process.env.UNI_INPUT_DIR, resourcePath) - } - }) + .options(fileLoaderOptions) + const staticTypes = ['images', 'media', 'fonts'] staticTypes.forEach(staticType => { webpackConfig.module @@ -164,12 +172,7 @@ const v3 = { limit: 1, fallback: { loader: 'file-loader', - options: { - emitFile: isAppView, - outputPath (url, resourcePath, context) { - return path.relative(process.env.UNI_INPUT_DIR, resourcePath) - } - } + options: fileLoaderOptions } })) }) -- GitLab