Skip to content

Commit

Permalink
快应用自定义组件调用,进行相对路径转换
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhouhu authored and luckyadam committed Dec 31, 2019
1 parent c984109 commit 7c042fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 2 additions & 7 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE, MINI_APP_FILES, NODE_MODUL
import { IComponentObj } from '../utils/types'
import { resolveScriptPath, buildUsingComponents, isNpmPkg, resolveNpmSync, isEmptyObject, promoteRelativePath, printLog, isAliasPath, replaceAliasPath } from '../utils'
import TaroSingleEntryDependency from '../dependencies/TaroSingleEntryDependency'
import { getTaroJsQuickAppComponentsPath, generateQuickAppUx, getImportTaroSelfComponents, generateQuickAppManifest } from '../utils/helper'
import { getTaroJsQuickAppComponentsPath, generateQuickAppUx, getImportTaroSelfComponents, getImportCustomComponents, generateQuickAppManifest } from '../utils/helper'
import parseAst from '../utils/parseAst'
import rewriterTemplate from '../quickapp/template-rewriter'

Expand Down Expand Up @@ -661,6 +661,7 @@ export default class MiniPlugin {
const scriptPath = file.path
const outputScriptPath = scriptPath.replace(this.sourceDir, this.outputDir).replace(path.extname(scriptPath), MINI_APP_FILES[buildAdapter].SCRIPT)
const importTaroSelfComponents = getImportTaroSelfComponents(outputScriptPath, this.options.nodeModulesPath, this.outputDir, taroSelfComponents)
const importCustomComponents = getImportCustomComponents(this.outputDir, depComponents)
const usingComponents = configObj.usingComponents
let importUsingComponent: any = new Set([])
if (usingComponents) {
Expand All @@ -671,12 +672,6 @@ export default class MiniPlugin {
}
}))
}
const importCustomComponents = new Set(depComponents.map(item => {
return {
path: item.path,
name: item.name as string
}
}))
template = generateQuickAppUx({
template,
imports: new Set([...importTaroSelfComponents, ...importUsingComponent, ...importCustomComponents])
Expand Down
13 changes: 13 additions & 0 deletions packages/taro-mini-runner/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export function getImportTaroSelfComponents (filePath, nodeModulesPath, outputDi
return importTaroSelfComponents
}

export function getImportCustomComponents(outputDir, depComponents) {
const importCustomComponents = new Set();
depComponents.forEach(item => {
const extnamePath = item.path.replace(path.extname(item.path), '')
const cRelativePath = path.relative(path.join(outputDir, 'index'), extnamePath).replace(/\\/g, '/')
importCustomComponents.add({
path: cRelativePath,
name: item.name
})
})
return importCustomComponents;
}

export function generateQuickAppUx ({
script,
template,
Expand Down

0 comments on commit 7c042fa

Please sign in to comment.