diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts index a59c300b31d1..3d4d4776217c 100644 --- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts @@ -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' @@ -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) { @@ -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]) diff --git a/packages/taro-mini-runner/src/utils/helper.ts b/packages/taro-mini-runner/src/utils/helper.ts index c6233c8aef94..eb0e1cc65d8c 100644 --- a/packages/taro-mini-runner/src/utils/helper.ts +++ b/packages/taro-mini-runner/src/utils/helper.ts @@ -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,