提交 64a8b213 编写于 作者: fxy060608's avatar fxy060608

feat(cli): easycom (uni_modules)

上级 cdbe8245
...@@ -359,11 +359,45 @@ function getAutoComponentsByDir (componentsPath, absolute = false) { ...@@ -359,11 +359,45 @@ function getAutoComponentsByDir (componentsPath, absolute = false) {
return components return components
} }
function initAutoImportScanComponents () { function initAutoComponents () {
const componentsPath = path.resolve(process.env.UNI_INPUT_DIR, 'components') const allComponents = {}
const componentsDirs = [path.resolve(process.env.UNI_INPUT_DIR, 'components')]
const components = getAutoComponentsByDir(componentsPath) global.uniModules.forEach(module => {
componentsDirs.push(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'components'))
})
componentsDirs.forEach(componentsDir => {
const currentComponents = getAutoComponentsByDir(componentsDir, true)
Object.keys(currentComponents).forEach(name => {
(allComponents[name] || (allComponents[name] = [])).push(currentComponents[name])
})
})
const components = {}
const conflictFiles = []
Object.keys(allComponents).forEach(name => {
const files = allComponents[name]
components[name] = files[0]
if (files.length > 1) {
conflictFiles.push(files)
}
})
if (conflictFiles.length > 0) {
conflictFiles.forEach(files => {
let usedFile
console.warn('easycom组件冲突:[' + files.map((file, index) => {
file = path.relative(process.env.UNI_INPUT_DIR, file)
if (index === 0) {
usedFile = file
}
return file
}).join(',') + '],优先使用:' + usedFile)
console.log('\n')
})
}
return components
}
function initAutoImportScanComponents () {
const components = initAutoComponents()
if (process.env.UNI_PLATFORM === 'quickapp-native') { if (process.env.UNI_PLATFORM === 'quickapp-native') {
if (!uniQuickAppAutoImportScanComponents) { if (!uniQuickAppAutoImportScanComponents) {
uniQuickAppAutoImportScanComponents = getAutoComponentsByDir( uniQuickAppAutoImportScanComponents = getAutoComponentsByDir(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册