Skip to content

Commit

Permalink
fix(cli): 小程序 watch 时新增组件样式文件不会被引入
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jun 14, 2018
1 parent 5521f60 commit bb9b0ca
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/taro-cli/src/weapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let appConfig = {}
const dependencyTree = {}
const depComponents = {}
const hasBeenBuiltComponents = []
const componentsBuildResult = {}
const wxssDepTree = {}
let isBuildingScripts = {}
let isBuildingStyles = {}
Expand Down Expand Up @@ -634,7 +635,6 @@ async function buildSinglePage (page) {
const res = parseAst(PARSE_AST_TYPE.PAGE, transformResult.ast, pageJs, outputPageJSPath)
const babelConfig = pluginsConfig.babel
const pageDepComponents = transformResult.components
depComponents[pageJs] = pageDepComponents
babelConfig && (babelConfig.babelrc = false)
let resCode = res.code
if (babelConfig) {
Expand Down Expand Up @@ -682,10 +682,8 @@ async function buildSinglePage (page) {
if (Util.isDifferentArray(fileDep['script'], res.scriptFiles)) {
compileDepScripts(babelConfig, res.scriptFiles)
}
console.log(fileDep['style'])
console.log(res.styleFiles)
// 编译样式文件
if (Util.isDifferentArray(fileDep['style'], res.styleFiles)) {
if (Util.isDifferentArray(fileDep['style'], res.styleFiles) || Util.isDifferentArray(depComponents[pageJs], pageDepComponents)) {
Util.printLog(Util.pocessTypeEnum.GENERATE, '页面WXSS', `${outputDirName}/${page}.wxss`)
const depStyleList = getDepStyleList(outputPageWXSSPath, buildDepComponentsResult)
wxssDepTree[outputPageWXSSPath] = depStyleList
Expand All @@ -698,6 +696,7 @@ async function buildSinglePage (page) {
if (Util.isDifferentArray(fileDep['media'], res.mediaFiles)) {
copyFilesFromSrcToOutput(res.mediaFiles)
}
depComponents[pageJs] = pageDepComponents
fileDep['style'] = res.styleFiles
fileDep['script'] = res.scriptFiles
fileDep['json'] = res.jsonFiles
Expand Down Expand Up @@ -779,12 +778,7 @@ function getRealComponentsPathList (filePath, components) {
}

function buildDepComponents (componentPathList) {
const promises = componentPathList.map(componentPath => {
if (hasBeenBuiltComponents.indexOf(componentPath) < 0) {
return buildSingleComponent(componentPath)
}
}).filter(item => item)
return Promise.all(promises)
return Promise.all(componentPathList.map(componentPath => buildSingleComponent(componentPath)))
}

function getDepStyleList (outputFilePath, buildDepComponentsResult) {
Expand All @@ -801,6 +795,9 @@ function getDepStyleList (outputFilePath, buildDepComponentsResult) {
}

async function buildSingleComponent (component) {
if (hasBeenBuiltComponents.indexOf(component) >= 0 && componentsBuildResult[component]) {
return componentsBuildResult[component]
}
let componentShowPath = component.replace(appPath + path.sep, '')
componentShowPath = componentShowPath.split(path.sep).join('/')
let outputComponentShowPath = componentShowPath.replace(sourceDirName, outputDirName)
Expand All @@ -819,7 +816,6 @@ async function buildSingleComponent (component) {
const res = parseAst(PARSE_AST_TYPE.COMPONENT, transformResult.ast, component, outputComponentJSPath)
const babelConfig = pluginsConfig.babel
const componentDepComponents = transformResult.components
depComponents[component] = componentDepComponents
babelConfig && (babelConfig.babelrc = false)
let resCode = res.code
if (babelConfig) {
Expand Down Expand Up @@ -864,7 +860,7 @@ async function buildSingleComponent (component) {
compileDepScripts(babelConfig, res.scriptFiles)
}
// 编译样式文件
if (Util.isDifferentArray(fileDep['style'], res.styleFiles)) {
if (Util.isDifferentArray(fileDep['style'], res.styleFiles) || Util.isDifferentArray(depComponents[component], componentDepComponents)) {
Util.printLog(Util.pocessTypeEnum.GENERATE, '组件WXSS', `${outputDirName}/${outputComponentShowPath}.wxss`)
const depStyleList = getDepStyleList(outputComponentWXSSPath, buildDepComponentsResult)
wxssDepTree[outputComponentWXSSPath] = depStyleList
Expand All @@ -883,11 +879,13 @@ async function buildSingleComponent (component) {
fileDep['json'] = res.jsonFiles
fileDep['media'] = res.mediaFiles
dependencyTree[component] = fileDep
return {
depComponents[component] = componentDepComponents
componentsBuildResult[component] = {
js: outputComponentJSPath,
wxss: outputComponentWXSSPath,
wxml: outputComponentWXMLPath
}
return componentsBuildResult[component]
} catch (err) {
console.log(err)
}
Expand Down

0 comments on commit bb9b0ca

Please sign in to comment.