提交 43e71a9f 编写于 作者: fxy060608's avatar fxy060608

refactor(cli): init auto import components options

上级 a7509f97
...@@ -328,6 +328,19 @@ function addPageUsingComponents (pagePath, usingComponents) { ...@@ -328,6 +328,19 @@ function addPageUsingComponents (pagePath, usingComponents) {
// 存储自动组件 // 存储自动组件
const autoComponentMap = {} const autoComponentMap = {}
let lastUsingAutoImportComponentsJson = ''
process.UNI_AUTO_COMPONENTS = []
function initAutoImportComponents (usingAutoImportComponents = {}) {
const newUsingAutoImportComponentsJson = JSON.stringify(usingAutoImportComponents)
if (newUsingAutoImportComponentsJson !== lastUsingAutoImportComponentsJson) {
lastUsingAutoImportComponentsJson = newUsingAutoImportComponentsJson
process.UNI_AUTO_COMPONENTS = parseUsingAutoImportComponents(usingAutoImportComponents)
refreshAutoComponentMap()
}
}
/** /**
* UNI_AUTO_COMPONENTS 被更新,重新刷新 map * UNI_AUTO_COMPONENTS 被更新,重新刷新 map
*/ */
...@@ -385,7 +398,7 @@ module.exports = { ...@@ -385,7 +398,7 @@ module.exports = {
parsePagesJson, parsePagesJson,
pagesJsonJsFileName, pagesJsonJsFileName,
getAutoComponents, getAutoComponents,
refreshAutoComponentMap, initAutoImportComponents,
addPageUsingComponents, addPageUsingComponents,
getUsingComponentsCode, getUsingComponentsCode,
generateUsingComponentsCode, generateUsingComponentsCode,
......
...@@ -308,6 +308,12 @@ if ( ...@@ -308,6 +308,12 @@ if (
} }
} }
const {
initAutoImportComponents
} = require('@dcloudio/uni-cli-shared/lib/pages')
initAutoImportComponents(pagesJsonObj.usingAutoImportComponents)
runByHBuilderX && console.log(`正在编译中...`) runByHBuilderX && console.log(`正在编译中...`)
module.exports = { module.exports = {
......
...@@ -18,8 +18,7 @@ const { ...@@ -18,8 +18,7 @@ const {
const { const {
pagesJsonJsFileName, pagesJsonJsFileName,
refreshAutoComponentMap, initAutoImportComponents
parseUsingAutoImportComponents
} = require('@dcloudio/uni-cli-shared/lib/pages') } = require('@dcloudio/uni-cli-shared/lib/pages')
const parseStyle = require('./util').parseStyle const parseStyle = require('./util').parseStyle
...@@ -33,17 +32,6 @@ function renameUsingComponents (jsonObj) { ...@@ -33,17 +32,6 @@ function renameUsingComponents (jsonObj) {
return jsonObj return jsonObj
} }
let lastUsingAutoImportComponentsJson = ''
function initAutoImportComponents (usingAutoImportComponents = {}) {
const newUsingAutoImportComponentsJson = JSON.stringify(usingAutoImportComponents)
if (newUsingAutoImportComponentsJson !== lastUsingAutoImportComponentsJson) {
lastUsingAutoImportComponentsJson = newUsingAutoImportComponentsJson
process.UNI_AUTO_COMPONENTS = parseUsingAutoImportComponents(usingAutoImportComponents)
refreshAutoComponentMap()
}
}
module.exports = function (content) { module.exports = function (content) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册