diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts index b8364f8cfca6..c3f918dab90d 100644 --- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts +++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts @@ -737,7 +737,7 @@ export default class MiniPlugin { } getComponents (compiler: webpack.Compiler, fileList: Set, isRoot: boolean) { - const { buildAdapter, alias, isBuildQuickapp, fileType, constantsReplaceList, nodeModulesPath } = this.options + const { buildAdapter, alias, isBuildQuickapp, fileType, constantsReplaceList, nodeModulesPath, isBuildPlugin } = this.options fileList.forEach(file => { try { const isNative = file.isNative @@ -824,7 +824,7 @@ export default class MiniPlugin { } taroFileTypeMap[file.path] = { type: isRoot ? PARSE_AST_TYPE.PAGE : PARSE_AST_TYPE.COMPONENT, - config: merge({}, isComponentConfig, buildUsingComponents(file.path, this.sourceDir, alias, depComponents), configObj), + config: merge({}, isComponentConfig, buildUsingComponents(file.path, this.sourceDir, alias, depComponents, isBuildPlugin), configObj), code, importStyles } diff --git a/packages/taro-mini-runner/src/utils/index.ts b/packages/taro-mini-runner/src/utils/index.ts index 3bf60b7621e4..9127403a87af 100644 --- a/packages/taro-mini-runner/src/utils/index.ts +++ b/packages/taro-mini-runner/src/utils/index.ts @@ -48,6 +48,7 @@ export function buildUsingComponents ( sourceDir: string, pathAlias: IOption, components: IComponentObj[], + isBuildPlugin: boolean, isComponent?: boolean ): IOption { const usingComponents = Object.create(null) @@ -59,7 +60,8 @@ export function buildUsingComponents ( componentPath = resolveScriptPath(path.resolve(filePath, '..', componentPath as string)) if (fs.existsSync(componentPath)) { if (NODE_MODULES_REG.test(componentPath) && !NODE_MODULES_REG.test(filePath)) { - componentPath = componentPath!.replace(NODE_MODULES_REG, path.join(sourceDir, 'npm')) + const npmDir = isBuildPlugin ? 'plugin/npm' : 'npm' + componentPath = componentPath!.replace(NODE_MODULES_REG, path.join(sourceDir, npmDir)) } componentPath = promoteRelativePath(path.relative(filePath, componentPath!)) } else {