diff --git a/core/src/index.ts b/core/src/index.ts index 8d88f8a..45d0572 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -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'); @@ -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) { diff --git a/core/src/utils.ts b/core/src/utils.ts index 4fe85d4..f4d0ddf 100644 --- a/core/src/utils.ts +++ b/core/src/utils.ts @@ -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 {