From f6461c06c3ccdd0638ec400a416caa028f7c54c0 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 10 Jul 2020 17:59:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=90=AB=E6=9C=89=E9=94=99=E8=AF=AF=E5=BC=95=E7=94=A8=E7=9A=84?= =?UTF-8?q?=20wxss=20=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/plugin/generate-component.js | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js index a999105ab..2be66a16f 100644 --- a/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js +++ b/packages/webpack-uni-mp-loader/lib/plugin/generate-component.js @@ -64,6 +64,7 @@ module.exports = function generateComponent (compilation) { const concatenatedModules = modules.filter(module => module.modules) const uniModuleId = modules.find(module => module.resource && normalizePath(module.resource) === uniPath).id + const wxssImports = {} Object.keys(assets).forEach(name => { if (components.has(name.replace('.js', ''))) { @@ -81,7 +82,7 @@ module.exports = function generateComponent (compilation) { let resource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, '..', modulePath)) const altResource = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, modulePath)) - if ( + if ( /^win/.test(process.platform) && modulePath.includes('@dcloudio') && ( @@ -125,6 +126,24 @@ module.exports = function generateComponent (compilation) { assets[name].source = newSource } } + if (name.endsWith('.wxss')) { + // 移除部分含有错误引用的 wxss 文件 + const origSource = assets[name].source().trim() + const result = origSource.match(/^@import ["'](.+?)["']$/) + if (result) { + const wxssPath = path.join(path.dirname(name), result[1]) + if (Object.keys(assets).includes(wxssPath)) { + wxssImports[wxssPath] = wxssImports[wxssPath] || [] + wxssImports[wxssPath].push(name) + } else { + if (wxssImports[name]) { + wxssImports[name].forEach(name => delete assets[name]) + delete wxssImports[name] + } + delete assets[name] + } + } + } }) } if (process.env.UNI_FEATURE_OBSOLETE !== 'false') { @@ -158,4 +177,4 @@ function removeUnusedComponent (name) { fs.renameSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'), path.join(process.env.UNI_OUTPUT_DIR, name + '.bak.json')) } catch (e) {} -} +} -- GitLab