Skip to content

Commit

Permalink
fix(jsx2mp-loader): 无法resolve的main字段不做修改
Browse files Browse the repository at this point in the history
  • Loading branch information
feisun authored and shiftj18 committed Aug 7, 2023
1 parent 64a4aaa commit 64b7aac
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/jsx2mp-loader/src/script-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ module.exports = function scriptLoader(content) {

const pkg = readJSONSync(sourcePackageJSONPath);
const npmName = pkg.name; // Update to real npm name, for that tnpm will create like `[email protected]@rax-view` folders.
const npmMainPath = join(sourcePackagePath, pkg.main || '');

let npmMainPath = join(sourcePackagePath, pkg.main || '');
try {
// compat pkg.main without suffix like `lib/index`
npmMainPath = require.resolve(npmMainPath);
} catch (e) {
// can't resolve npmMainPath
}
const isUsingMainMiniappComponent = pkg.hasOwnProperty(MINIAPP_CONFIG_FIELD) && this.resourcePath === npmMainPath;
// Is miniapp compatible component.
if (isUsingMainMiniappComponent || isRelativeMiniappComponent || isThirdMiniappComponent) {
Expand Down

0 comments on commit 64b7aac

Please sign in to comment.