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 a999105ab5aaa7cf46cedb0541c1cbe230250826..2be66a16fece6d1b19967f75cf2e928a767794f7 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) {} -} +}