Skip to content

Commit

Permalink
fix(cli): 快应用支持多端组件,close #3685
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jul 8, 2019
1 parent 2dfeafe commit adf68af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
15 changes: 9 additions & 6 deletions packages/taro-cli/src/mini/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export async function buildSingleComponent (
})
transfromNativeComponents(outputComponentJSONPath.replace(buildConfig.outputDir || buildOutputDir, sourceDirPath), res.configObj)
}
let realComponentsPathList: IComponentObj[] = []
realComponentsPathList = getRealComponentsPathList(component, componentDepComponents)

if (!isQuickApp) {
resCode = await compileScriptFile(resCode, component, outputComponentJSPath, buildAdapter)
if (isProduction) {
Expand All @@ -262,9 +265,11 @@ export async function buildSingleComponent (
} else {
// 快应用编译,搜集创建组件 ux 文件
const importTaroSelfComponents = getImportTaroSelfComponents(outputComponentJSPath, res.taroSelfComponents)
const importCustomComponents = new Set(componentDepComponents.map(item => {
delete item.type
return item
const importCustomComponents = new Set(realComponentsPathList.map(item => {
return {
path: path.relative(path.dirname(component), item.path as string).replace(path.extname(item.path as string), ''),
name: item.name as string
}
}))
let styleRelativePath
if (res.styleFiles.length) {
Expand All @@ -288,9 +293,7 @@ export async function buildSingleComponent (
media: []
}
// 编译依赖的组件文件
let realComponentsPathList: IComponentObj[] = []
if (componentDepComponents.length) {
realComponentsPathList = getRealComponentsPathList(component, componentDepComponents)
if (realComponentsPathList.length) {
res.scriptFiles = res.scriptFiles.map(item => {
for (let i = 0; i < realComponentsPathList.length; i++) {
const componentObj = realComponentsPathList[i]
Expand Down
4 changes: 2 additions & 2 deletions packages/taro-cli/src/mini/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function getRealComponentsPathList (
): IComponentObj[] {
const { appPath, isProduction, buildAdapter, projectConfig, npmConfig } = BuildData
const pathAlias = projectConfig.alias || {}
return components.map(component => {
return components.length ? components.map(component => {
let componentPath = component.path
if (isAliasPath(componentPath as string, pathAlias)) {
componentPath = replaceAliasPath(filePath, componentPath as string, pathAlias)
Expand All @@ -262,7 +262,7 @@ export function getRealComponentsPathList (
name: component.name,
type: component.type
}
})
}) : []
}

export function isFileToBePage (filePath: string): boolean {
Expand Down
15 changes: 9 additions & 6 deletions packages/taro-cli/src/mini/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ export async function buildSinglePage (page: string) {
transfromNativeComponents(outputPageJSONPath.replace(outputDir, sourceDir), res.configObj)
}

let realComponentsPathList: IComponentObj[] = []
realComponentsPathList = getRealComponentsPathList(pageJs, pageDepComponents)

if (!isQuickApp) {
resCode = await compileScriptFile(resCode, pageJs, outputPageJSPath, buildAdapter)
if (isProduction) {
Expand All @@ -161,9 +164,11 @@ export async function buildSinglePage (page: string) {
} else {
// 快应用编译,搜集创建页面 ux 文件
const importTaroSelfComponents = getImportTaroSelfComponents(outputPageJSPath, res.taroSelfComponents)
const importCustomComponents = new Set(pageDepComponents.map(item => {
delete item.type
return item
const importCustomComponents = new Set(realComponentsPathList.map(item => {
return {
path: path.relative(path.dirname(pageJs), item.path as string).replace(path.extname(item.path as string), ''),
name: item.name as string
}
}))
// 生成页面 ux 文件
let styleRelativePath
Expand All @@ -180,9 +185,7 @@ export async function buildSinglePage (page: string) {
printLog(processTypeEnum.GENERATE, '页面文件', `${outputDirName}/${page}${outputFilesTypes.TEMPL}`)
}
// 编译依赖的组件文件
let realComponentsPathList: IComponentObj[] = []
if (pageDepComponents.length) {
realComponentsPathList = getRealComponentsPathList(pageJs, pageDepComponents)
if (realComponentsPathList.length) {
res.scriptFiles = res.scriptFiles.map(item => {
for (let i = 0; i < realComponentsPathList.length; i++) {
const componentObj = realComponentsPathList[i]
Expand Down

0 comments on commit adf68af

Please sign in to comment.