diff --git a/packages/taro-cli/src/mini/astProcess.ts b/packages/taro-cli/src/mini/astProcess.ts index c6d1946fc917..8fab73b19c64 100644 --- a/packages/taro-cli/src/mini/astProcess.ts +++ b/packages/taro-cli/src/mini/astProcess.ts @@ -49,6 +49,7 @@ import { } from '../util/astConvert' import babylonConfig from '../config/babylon' import { getExactedNpmFilePath, getNotExistNpmList } from '../util/npmExact' +import { excludeReplaceTaroFrameworkPkgs } from '../util/resolve_npm_files' import { IComponentObj } from './interface' import { @@ -490,7 +491,10 @@ export function parseAst ( if (defaultSpecifier) { taroImportDefaultName = defaultSpecifier } - value = taroMiniAppFramework + excludeReplaceTaroFrameworkPkgs.add(taroMiniAppFramework) + if (!Array.from(excludeReplaceTaroFrameworkPkgs).some(item => sourceFilePath.replace(/\\/g, '/').indexOf(item) >= 0)) { + value = taroMiniAppFramework + } } else if (value === taroJsRedux) { specifiers.forEach(item => { if (item.type === 'ImportSpecifier') { @@ -592,7 +596,10 @@ export function parseAst ( const id = parentNode.declarations[0].id if (value === taroJsFramework && id.type === 'Identifier') { taroImportDefaultName = id.name - value = taroMiniAppFramework + excludeReplaceTaroFrameworkPkgs.add(taroMiniAppFramework) + if (!Array.from(excludeReplaceTaroFrameworkPkgs).some(item => sourceFilePath.replace(/\\/g, '/').indexOf(item) >= 0)) { + value = taroMiniAppFramework + } } else if (value === taroJsRedux) { const declarations = parentNode.declarations declarations.forEach(item => { diff --git a/packages/taro-cli/src/util/resolve_npm_files.ts b/packages/taro-cli/src/util/resolve_npm_files.ts index febaee160710..f44619867f05 100644 --- a/packages/taro-cli/src/util/resolve_npm_files.ts +++ b/packages/taro-cli/src/util/resolve_npm_files.ts @@ -44,7 +44,7 @@ const excludeNpmPkgs = ['ReactPropTypes'] const resolvedCache: IResolvedCache = {} const copyedFiles = {} -const excludeReplaceTaroFrameworkPkgs = new Set([taroJsRedux, taroJsMobx, taroJsMobxCommon]) +export const excludeReplaceTaroFrameworkPkgs = new Set([taroJsRedux, taroJsMobx, taroJsMobxCommon]) export function resolveNpmPkgMainPath ( pkgName: string,