Skip to content

Commit

Permalink
fix: fix build nodejs bundle error.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 2, 2023
1 parent eff26a3 commit 02dcae6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { overridePaths } from 'kkt/lib/overrides/paths';
import { sync as gzipSize } from 'gzip-size';
import filesize from 'filesize';
import './overrides';
import { filterPlugins, removeLoaders, hasTypeModule } from './utils';
import { filterPlugins, modifyNodeJSLoaders, removeLoaders, hasTypeModule } from './utils';

function help() {
const { version } = require('../package.json');
Expand Down Expand Up @@ -221,7 +221,7 @@ process.on('exit', (code) => {
if (isWeb) {
conf = removeLoaders(conf);
} else {
conf.module.rules = [];
conf = modifyNodeJSLoaders(conf);
}
conf.entry = inputFile;
if (argvs.sourceMap) {
Expand Down
22 changes: 22 additions & 0 deletions core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ export function removeLoaders(conf: WebpackConfiguration) {
return conf;
}

export function modifyNodeJSLoaders(conf: WebpackConfiguration) {
conf.module.rules = conf.module.rules.map((rule) => {
if (typeof rule === 'object' && rule.oneOf) {
rule.oneOf = rule.oneOf
.map((item) =>
item &&
item.exclude &&
/@babel(?:\/|\\{1,2})runtime/.toString() === item.exclude.toString() &&
item.test.toString() === /\.(js|mjs)$/.toString()
? {
...item,
test: /\.(js|cjs|mjs)$/,
}
: item,
)
.filter(Boolean);
}
return rule;
});
return conf;
}

export function hasTypeModule(path: string) {
while (path !== (path = PATH.resolve(path, '..'))) {
try {
Expand Down

0 comments on commit 02dcae6

Please sign in to comment.