提交 4b64e805 编写于 作者: fxy060608's avatar fxy060608

fix(mp): remove unused component (question/82087)

上级 1ddda81c
const fs = require('fs')
const path = require('path')
const {
removeExt,
......@@ -50,8 +51,10 @@ function findComponentModuleId (modules, concatenatedModules, resource, altResou
resource
}
let lastComponents = []
// TODO 解决方案不太理想
module.exports = function generateComponent (compilation) {
const curComponents = []
const components = getComponentSet()
if (components.size) {
const assets = compilation.assets
......@@ -62,6 +65,7 @@ module.exports = function generateComponent (compilation) {
Object.keys(assets).forEach(name => {
if (components.has(name.replace('.js', ''))) {
curComponents.push(name.replace('.js', ''))
const chunkName = name.replace('.js', '-create-component')
let moduleId = ''
......@@ -107,4 +111,20 @@ module.exports = function generateComponent (compilation) {
}
})
}
if (process.env.UNI_FEATURE_OBSOLETE !== false) {
if (lastComponents.length) {
for (const name of lastComponents) {
if (!curComponents.includes(name)) {
removeUnusedComponent(name)
}
}
}
lastComponents = curComponents
}
}
function removeUnusedComponent (name) {
try {
fs.unlinkSync(path.join(process.env.UNI_OUTPUT_DIR, name + '.json'))
} catch (e) {}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册