From 656a8107b8c2d2c7e2e8f939de9aa81a888d90a1 Mon Sep 17 00:00:00 2001 From: liaofeiyin <13296605969@163.com> Date: Thu, 9 Dec 2021 10:49:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(webpack-uni-app-loader):=20require=20?= =?UTF-8?q?=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webpack-uni-mp-loader/lib/plugin/index-new.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js index 9aa2ef5d5..ddc26facb 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/index-new.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/index-new.js @@ -47,9 +47,11 @@ function addSubPackagesRequire (compilation) { name.indexOf(root + '/') === 0 && name !== subPackageVendorPath ) { - const source = - `require('${normalizePath(path.relative(path.dirname(name), subPackageVendorPath))}');` + - compilation.assets[name].source() + let relativePath = normalizePath(path.relative(path.dirname(name), subPackageVendorPath)) + if (!relativePath.startsWith('.')) { + relativePath = './' + relativePath + } + const source = `require('${relativePath}');` + compilation.assets[name].source() compilation.assets[name] = { size () { -- GitLab