From 2b94787258cfaa0db0ffcc842e8669d056ba9cee Mon Sep 17 00:00:00 2001 From: xierenyuan Date: Wed, 30 Jul 2025 10:31:42 +0800 Subject: [PATCH 1/2] feat: add transformImport feature for module path conversion --- .gitignore | 3 +- examples/ant-pro/config/config.ts | 9 +- .../compiled/babel-plugin-import/index.d.ts | 1 + .../compiled/babel-plugin-import/index.js | 481 ++++++++++++++++++ .../compiled/babel-plugin-import/package.json | 1 + packages/preset-bundler/package.json | 3 + packages/preset-bundler/prebundle.config.mjs | 12 + .../transformImport/transformImport.ts | 131 +++++ packages/preset-bundler/src/index.ts | 1 + pnpm-lock.yaml | 28 +- 10 files changed, 648 insertions(+), 22 deletions(-) create mode 100644 packages/preset-bundler/compiled/babel-plugin-import/index.d.ts create mode 100644 packages/preset-bundler/compiled/babel-plugin-import/index.js create mode 100644 packages/preset-bundler/compiled/babel-plugin-import/package.json create mode 100644 packages/preset-bundler/prebundle.config.mjs create mode 100644 packages/preset-bundler/src/features/transformImport/transformImport.ts diff --git a/.gitignore b/.gitignore index 8503ea5..3db8996 100644 --- a/.gitignore +++ b/.gitignore @@ -67,4 +67,5 @@ examples/*/.vscode /.idea .umi -.umi-* \ No newline at end of file +.umi-* +.takumi/todos diff --git a/examples/ant-pro/config/config.ts b/examples/ant-pro/config/config.ts index b98c48b..0866bcd 100644 --- a/examples/ant-pro/config/config.ts +++ b/examples/ant-pro/config/config.ts @@ -157,5 +157,12 @@ export default defineConfig({ }, esbuildMinifyIIFE: true, requestRecord: {}, - rspack: {} + rspack: {}, + transformImport: [ + { + libraryName: 'antd', + libraryDirectory: 'es', + style: false, + }, + ], }); diff --git a/packages/preset-bundler/compiled/babel-plugin-import/index.d.ts b/packages/preset-bundler/compiled/babel-plugin-import/index.d.ts new file mode 100644 index 0000000..a2ac5f9 --- /dev/null +++ b/packages/preset-bundler/compiled/babel-plugin-import/index.d.ts @@ -0,0 +1 @@ +export = any; diff --git a/packages/preset-bundler/compiled/babel-plugin-import/index.js b/packages/preset-bundler/compiled/babel-plugin-import/index.js new file mode 100644 index 0000000..9bc0ea7 --- /dev/null +++ b/packages/preset-bundler/compiled/babel-plugin-import/index.js @@ -0,0 +1,481 @@ +/******/ (() => { // webpackBootstrap +/******/ var __webpack_modules__ = ({ + +/***/ 523: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/Plugin.js +var Plugin_exports = {}; +__export(Plugin_exports, { + default: () => Plugin +}); +module.exports = __toCommonJS(Plugin_exports); +var import_path = __nccwpck_require__(17); +var import_helper_module_imports = __nccwpck_require__(68); +function transCamel(_str, symbol) { + const cells = _str.match(/([A-Z]+(?=[A-Z]|$))|([A-Z]?[^A-Z]+)/g) || []; + return cells.map((c) => c.toLowerCase()).join(symbol); +} +function winPath(path) { + return path.replace(/\\/g, "/"); +} +function normalizeCustomName(originCustomName) { + if (typeof originCustomName === "string") { + const customNameExports = require(originCustomName); + return typeof customNameExports === "function" ? customNameExports : customNameExports.default; + } + return originCustomName; +} +var Plugin = class { + constructor(libraryName, libraryDirectory, style, styleLibraryDirectory, customStyleName, camel2DashComponentName, camel2UnderlineComponentName, fileName, customName, transformToDefaultImport, types, index = 0) { + this.libraryName = libraryName; + this.libraryDirectory = typeof libraryDirectory === "undefined" ? "lib" : libraryDirectory; + this.camel2DashComponentName = typeof camel2DashComponentName === "undefined" ? true : camel2DashComponentName; + this.camel2UnderlineComponentName = camel2UnderlineComponentName; + this.style = style || false; + this.styleLibraryDirectory = styleLibraryDirectory; + this.customStyleName = normalizeCustomName(customStyleName); + this.fileName = fileName || ""; + this.customName = normalizeCustomName(customName); + this.transformToDefaultImport = typeof transformToDefaultImport === "undefined" ? true : transformToDefaultImport; + this.types = types; + this.pluginStateKey = `importPluginState${index}`; + } + getPluginState(state) { + if (!state[this.pluginStateKey]) { + state[this.pluginStateKey] = {}; + } + return state[this.pluginStateKey]; + } + importMethod(methodName, file, pluginState) { + if (!pluginState.selectedMethods[methodName]) { + const { style, libraryDirectory } = this; + const transformedMethodName = this.camel2UnderlineComponentName ? transCamel(methodName, "_") : this.camel2DashComponentName ? transCamel(methodName, "-") : methodName; + const path = winPath( + this.customName ? this.customName(transformedMethodName, file) : (0, import_path.join)(this.libraryName, libraryDirectory, transformedMethodName, this.fileName) + // eslint-disable-line + ); + pluginState.selectedMethods[methodName] = this.transformToDefaultImport ? (0, import_helper_module_imports.addDefault)(file.path, path, { nameHint: methodName }) : (0, import_helper_module_imports.addNamed)(file.path, methodName, path); + if (this.customStyleName) { + const stylePath = winPath(this.customStyleName(transformedMethodName, file)); + (0, import_helper_module_imports.addSideEffect)(file.path, `${stylePath}`); + } else if (this.styleLibraryDirectory) { + const stylePath = winPath( + (0, import_path.join)(this.libraryName, this.styleLibraryDirectory, transformedMethodName, this.fileName) + ); + (0, import_helper_module_imports.addSideEffect)(file.path, `${stylePath}`); + } else if (style === true) { + (0, import_helper_module_imports.addSideEffect)(file.path, `${path}/style`); + } else if (style === "css") { + (0, import_helper_module_imports.addSideEffect)(file.path, `${path}/style/css`); + } else if (typeof style === "function") { + const stylePath = style(path, file); + if (stylePath) { + (0, import_helper_module_imports.addSideEffect)(file.path, stylePath); + } + } + } + return { ...pluginState.selectedMethods[methodName] }; + } + buildExpressionHandler(node, props, path, state) { + const file = path && path.hub && path.hub.file || state && state.file; + const { types } = this; + const pluginState = this.getPluginState(state); + props.forEach((prop) => { + if (!types.isIdentifier(node[prop])) + return; + if (pluginState.specified[node[prop].name] && types.isImportSpecifier(path.scope.getBinding(node[prop].name).path)) { + node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); + } + }); + } + buildDeclaratorHandler(node, prop, path, state) { + const file = path && path.hub && path.hub.file || state && state.file; + const { types } = this; + const pluginState = this.getPluginState(state); + const checkScope = (targetNode) => pluginState.specified[targetNode.name] && // eslint-disable-line + path.scope.hasBinding(targetNode.name) && // eslint-disable-line + path.scope.getBinding(targetNode.name).path.type === "ImportSpecifier"; + if (types.isIdentifier(node[prop]) && checkScope(node[prop])) { + node[prop] = this.importMethod(pluginState.specified[node[prop].name], file, pluginState); + } else if (types.isSequenceExpression(node[prop])) { + node[prop].expressions.forEach((expressionNode, index) => { + if (types.isIdentifier(expressionNode) && checkScope(expressionNode)) { + node[prop].expressions[index] = this.importMethod( + pluginState.specified[expressionNode.name], + file, + pluginState + ); + } + }); + } + } + ProgramEnter(path, state) { + const pluginState = this.getPluginState(state); + pluginState.specified = /* @__PURE__ */ Object.create(null); + pluginState.libraryObjs = /* @__PURE__ */ Object.create(null); + pluginState.selectedMethods = /* @__PURE__ */ Object.create(null); + pluginState.pathsToRemove = []; + } + ProgramExit(path, state) { + this.getPluginState(state).pathsToRemove.forEach((p) => !p.removed && p.remove()); + } + ImportDeclaration(path, state) { + const { node } = path; + if (!node) + return; + const { value } = node.source; + const { libraryName } = this; + const { types } = this; + const pluginState = this.getPluginState(state); + if (value === libraryName) { + node.specifiers.forEach((spec) => { + if (types.isImportSpecifier(spec)) { + pluginState.specified[spec.local.name] = spec.imported.name; + } else { + pluginState.libraryObjs[spec.local.name] = true; + } + }); + pluginState.pathsToRemove.push(path); + } + } + CallExpression(path, state) { + const { node } = path; + const file = path && path.hub && path.hub.file || state && state.file; + const { name } = node.callee; + const { types } = this; + const pluginState = this.getPluginState(state); + if (types.isIdentifier(node.callee)) { + if (pluginState.specified[name]) { + node.callee = this.importMethod(pluginState.specified[name], file, pluginState); + } + } + node.arguments = node.arguments.map((arg) => { + const { name: argName } = arg; + if (pluginState.specified[argName] && path.scope.hasBinding(argName) && path.scope.getBinding(argName).path.type === "ImportSpecifier") { + return this.importMethod(pluginState.specified[argName], file, pluginState); + } + return arg; + }); + } + MemberExpression(path, state) { + const { node } = path; + const file = path && path.hub && path.hub.file || state && state.file; + const pluginState = this.getPluginState(state); + if (!node.object || !node.object.name) + return; + if (pluginState.libraryObjs[node.object.name]) { + path.replaceWith(this.importMethod(node.property.name, file, pluginState)); + } else if (pluginState.specified[node.object.name] && path.scope.hasBinding(node.object.name)) { + const { scope } = path.scope.getBinding(node.object.name); + if (scope.path.parent.type === "File") { + node.object = this.importMethod(pluginState.specified[node.object.name], file, pluginState); + } + } + } + Property(path, state) { + const { node } = path; + this.buildDeclaratorHandler(node, "value", path, state); + } + VariableDeclarator(path, state) { + const { node } = path; + this.buildDeclaratorHandler(node, "init", path, state); + } + ArrayExpression(path, state) { + const { node } = path; + const props = node.elements.map((_, index) => index); + this.buildExpressionHandler(node.elements, props, path, state); + } + LogicalExpression(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["left", "right"], path, state); + } + ConditionalExpression(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["test", "consequent", "alternate"], path, state); + } + IfStatement(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["test"], path, state); + this.buildExpressionHandler(node.test, ["left", "right"], path, state); + } + ExpressionStatement(path, state) { + const { node } = path; + const { types } = this; + if (types.isAssignmentExpression(node.expression)) { + this.buildExpressionHandler(node.expression, ["right"], path, state); + } + } + ReturnStatement(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["argument"], path, state); + } + ExportDefaultDeclaration(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["declaration"], path, state); + } + BinaryExpression(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["left", "right"], path, state); + } + NewExpression(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["callee"], path, state); + const argumentsProps = node.arguments.map((_, index) => index); + this.buildExpressionHandler(node.arguments, argumentsProps, path, state); + } + SwitchStatement(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["discriminant"], path, state); + } + SwitchCase(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["test"], path, state); + } + ClassDeclaration(path, state) { + const { node } = path; + this.buildExpressionHandler(node, ["superClass"], path, state); + } + SequenceExpression(path, state) { + const { node } = path; + const expressionsProps = node.expressions.map((_, index) => index); + this.buildExpressionHandler(node.expressions, expressionsProps, path, state); + } +}; + + +/***/ }), + +/***/ 26: +/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { + +var __create = Object.create; +var __defProp = Object.defineProperty; +var __getOwnPropDesc = Object.getOwnPropertyDescriptor; +var __getOwnPropNames = Object.getOwnPropertyNames; +var __getProtoOf = Object.getPrototypeOf; +var __hasOwnProp = Object.prototype.hasOwnProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; +var __copyProps = (to, from, except, desc) => { + if (from && typeof from === "object" || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); + } + return to; +}; +var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( + // If the importer is in node compatibility mode or this is not an ESM + // file that has been converted to a CommonJS file using a Babel- + // compatible transform (i.e. "__esModule" has not been set), then set + // "default" to the CommonJS "module.exports" for node compatibility. + isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, + mod +)); +var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); + +// src/index.js +var src_exports = {}; +__export(src_exports, { + default: () => src_default +}); +module.exports = __toCommonJS(src_exports); +var import_assert = __toESM(__nccwpck_require__(491)); +var import_Plugin = __toESM(__nccwpck_require__(523)); +function src_default({ types }) { + let plugins = null; + global.__clearBabelAntdPlugin = () => { + plugins = null; + }; + function applyInstance(method, args, context) { + for (const plugin of plugins) { + if (plugin[method]) { + plugin[method].apply(plugin, [...args, context]); + } + } + } + const Program = { + enter(path, { opts = {} }) { + if (!plugins) { + if (Array.isArray(opts)) { + plugins = opts.map( + ({ + libraryName, + libraryDirectory, + style, + styleLibraryDirectory, + customStyleName, + camel2DashComponentName, + camel2UnderlineComponentName, + fileName, + customName, + transformToDefaultImport + }, index) => { + (0, import_assert.default)(libraryName, "libraryName should be provided"); + return new import_Plugin.default( + libraryName, + libraryDirectory, + style, + styleLibraryDirectory, + customStyleName, + camel2DashComponentName, + camel2UnderlineComponentName, + fileName, + customName, + transformToDefaultImport, + types, + index + ); + } + ); + } else { + (0, import_assert.default)(opts.libraryName, "libraryName should be provided"); + plugins = [ + new import_Plugin.default( + opts.libraryName, + opts.libraryDirectory, + opts.style, + opts.styleLibraryDirectory, + opts.customStyleName, + opts.camel2DashComponentName, + opts.camel2UnderlineComponentName, + opts.fileName, + opts.customName, + opts.transformToDefaultImport, + types + ) + ]; + } + } + applyInstance("ProgramEnter", arguments, this); + }, + exit() { + applyInstance("ProgramExit", arguments, this); + } + }; + const methods = [ + "ImportDeclaration", + "CallExpression", + "MemberExpression", + "Property", + "VariableDeclarator", + "ArrayExpression", + "LogicalExpression", + "ConditionalExpression", + "IfStatement", + "ExpressionStatement", + "ReturnStatement", + "ExportDefaultDeclaration", + "BinaryExpression", + "NewExpression", + "ClassDeclaration", + "SwitchStatement", + "SwitchCase", + "SequenceExpression" + ]; + const ret = { + visitor: { Program } + }; + for (const method of methods) { + ret.visitor[method] = function() { + applyInstance(method, arguments, ret.visitor); + }; + } + return ret; +} + + +/***/ }), + +/***/ 68: +/***/ ((module) => { + +"use strict"; +module.exports = require("@kmijs/bundler-compiled/compiled/babel/helper-module-imports"); + +/***/ }), + +/***/ 491: +/***/ ((module) => { + +"use strict"; +module.exports = require("assert"); + +/***/ }), + +/***/ 17: +/***/ ((module) => { + +"use strict"; +module.exports = require("path"); + +/***/ }) + +/******/ }); +/************************************************************************/ +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __nccwpck_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ var threw = true; +/******/ try { +/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); +/******/ threw = false; +/******/ } finally { +/******/ if(threw) delete __webpack_module_cache__[moduleId]; +/******/ } +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ +/******/ /* webpack/runtime/compat */ +/******/ +/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; +/******/ +/************************************************************************/ +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __nccwpck_require__(26); +/******/ module.exports = __webpack_exports__; +/******/ +/******/ })() +; \ No newline at end of file diff --git a/packages/preset-bundler/compiled/babel-plugin-import/package.json b/packages/preset-bundler/compiled/babel-plugin-import/package.json new file mode 100644 index 0000000..8048ffa --- /dev/null +++ b/packages/preset-bundler/compiled/babel-plugin-import/package.json @@ -0,0 +1 @@ +{"name":"babel-plugin-import","author":"chencheng ","version":"1.13.8","license":"MIT","types":"index.d.ts","type":"commonjs"} diff --git a/packages/preset-bundler/package.json b/packages/preset-bundler/package.json index 15fddfc..f1befca 100644 --- a/packages/preset-bundler/package.json +++ b/packages/preset-bundler/package.json @@ -29,10 +29,12 @@ "build": "father build", "build:deps": "kmi-scripts bundleDeps", "dev": "father dev", + "prebundle": "prebundle", "prepublishOnly": "pnpm build" }, "dependencies": { "@kmijs/babel-preset-react": "workspace:*", + "@kmijs/bundler-compiled": "workspace:*", "@kmijs/bundler-rspack": "workspace:*", "@kmijs/bundler-shared": "workspace:*", "@kmijs/bundler-webpack": "workspace:*", @@ -44,6 +46,7 @@ "react-refresh": "0.14.0" }, "devDependencies": { + "babel-plugin-import": "1.13.8", "umi": "^4.4.11" }, "engines": { diff --git a/packages/preset-bundler/prebundle.config.mjs b/packages/preset-bundler/prebundle.config.mjs new file mode 100644 index 0000000..68076bf --- /dev/null +++ b/packages/preset-bundler/prebundle.config.mjs @@ -0,0 +1,12 @@ +/** @type {import('prebundle').Config} */ +export default { + dependencies: [ + { + name: 'babel-plugin-import', + ignoreDts: true, + externals: { + '@babel/helper-module-imports': '@kmijs/bundler-compiled/compiled/babel/helper-module-imports' + }, + }, + ], +}; diff --git a/packages/preset-bundler/src/features/transformImport/transformImport.ts b/packages/preset-bundler/src/features/transformImport/transformImport.ts new file mode 100644 index 0000000..6db8d2f --- /dev/null +++ b/packages/preset-bundler/src/features/transformImport/transformImport.ts @@ -0,0 +1,131 @@ +import { Mustache } from '@kmijs/shared' +import type { IApi } from '@kmijs/types' + +type TransformImport = Array<{ + libraryName: string + libraryDirectory?: string + style?: string | boolean + styleLibraryDirectory?: string + camelToDashComponentName?: boolean + transformToDefaultImport?: boolean + customName?: string + customStyleName?: string +}> + +export default (api: IApi) => { + api.describe({ + key: 'transformImport', + config: { + schema({ zod }) { + return zod + .array( + zod.object({ + libraryName: zod.string().describe('需要转换的库名'), + libraryDirectory: zod + .string() + .optional() + .describe( + '用于拼接转换后的路径,默认值 lib 拼接规则为 ${libraryName}/${libraryDirectory}/${member},其中 member 为引入成员。', + ), + + style: zod + .union([zod.string(), zod.boolean()]) + .optional() + .describe( + '确定是否需要引入相关样式,若为 true,则会引入路径 ${libraryName}/${libraryDirectory}/${member}/style。若为 false 或 undefined 则不会引入样式。', + ), + styleLibraryDirectory: zod + .string() + .optional() + .describe( + '该配置用于拼接引入样式时的引入路径,若该配置被指定,则 style 配置项会被忽略。拼接引入路径为 ${libraryName}/${styleLibraryDirectory}/${member}。', + ), + camelToDashComponentName: zod + .boolean() + .optional() + .describe( + '是否需要将 camelCase 的引入转换成 kebab-case。默认 true ', + ), + transformToDefaultImport: zod + .boolean() + .optional() + .describe('是否将导入语句转换成默认导入。默认 true'), + customName: zod + .string() + .optional() + .describe('自定义转换后的导入路径。'), + customStyleName: zod + .string() + .optional() + .describe( + '自定义转换后的样式导入路径,用法与 customName 一致。', + ), + }), + ) + .describe( + '转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 babel-plugin-impor', + ) + }, + }, + enableBy: api.EnableBy.config, + }) + + api.addExtraBabelPlugins(() => { + if (api.config.rspack) { + return [] + } + const transformImport = api.config.transformImport as TransformImport + return transformImport.map((item) => { + const { + libraryName, + libraryDirectory, + camelToDashComponentName, + style, + transformToDefaultImport, + customName, + customStyleName, + } = item + const importOpts: Record = { + libraryName, + libraryDirectory, + camel2DashComponentName: camelToDashComponentName, + style, + transformToDefaultImport, + } + + if (typeof style === 'string' && style.includes('{{')) { + importOpts.style = (member: string) => { + return Mustache.render(style, { member }) + } + } + + if (customName) { + importOpts.customName = (member: string) => { + return Mustache.render(customName, { member }) + } + } + + if (customStyleName) { + importOpts.customStyleName = (member: string) => { + return Mustache.render(customStyleName, { member }) + } + } + + return [ + require.resolve('../../../compiled/babel-plugin-import'), + importOpts, + libraryName, + ] + }) + }) + + api.modifySwcLoaderOptions((memo) => { + const { transformImport } = api.config + if (transformImport) { + memo.rspackExperiments ??= {} + memo.rspackExperiments.import ??= [] + memo.rspackExperiments.import.push(...transformImport) + } + return memo + }) +} diff --git a/packages/preset-bundler/src/index.ts b/packages/preset-bundler/src/index.ts index f4d3c10..351ad80 100644 --- a/packages/preset-bundler/src/index.ts +++ b/packages/preset-bundler/src/index.ts @@ -17,6 +17,7 @@ export default (api: IApi) => { require.resolve('./features/define/define'), require.resolve('./features/codeSplitting/codeSplitting'), require.resolve('./features/removeConsole/removeConsole'), + require.resolve('./features/transformImport/transformImport'), // plugins require.resolve('@kmijs/plugin-svgr'), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ae67a10..9f7d620 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -986,6 +986,9 @@ importers: '@kmijs/babel-preset-react': specifier: workspace:* version: link:../babel-preset-react + '@kmijs/bundler-compiled': + specifier: workspace:* + version: link:../bundler-compiled '@kmijs/bundler-rspack': specifier: workspace:* version: link:../bundler-rspack @@ -1014,6 +1017,9 @@ importers: specifier: 0.14.0 version: 0.14.0 devDependencies: + babel-plugin-import: + specifier: 1.13.8 + version: 1.13.8 umi: specifier: ^4.4.11 version: 4.4.11(@types/node@20.8.9)(@types/react@18.0.26)(prettier@3.0.3)(typescript@5.2.2) @@ -6603,15 +6609,6 @@ packages: '@napi-rs/nice-win32-x64-msvc': 1.0.1 optional: true - /@napi-rs/wasm-runtime@0.2.10: - resolution: {integrity: sha512-bCsCyeZEwVErsGmyPNSzwfwFn4OdxBj0mmv6hOFucB/k81Ojdu68RbZdxYsRQUPc9l6SU5F/cG+bXgWs3oUgsQ==} - requiresBuild: true - dependencies: - '@emnapi/core': 1.4.3 - '@emnapi/runtime': 1.4.3 - '@tybys/wasm-util': 0.9.0 - optional: true - /@napi-rs/wasm-runtime@0.2.12: resolution: {integrity: sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ==} requiresBuild: true @@ -6619,7 +6616,6 @@ packages: '@emnapi/core': 1.4.3 '@emnapi/runtime': 1.4.3 '@tybys/wasm-util': 0.10.0 - dev: false optional: true /@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1: @@ -6724,7 +6720,7 @@ packages: cpu: [wasm32] requiresBuild: true dependencies: - '@napi-rs/wasm-runtime': 0.2.10 + '@napi-rs/wasm-runtime': 0.2.12 dev: false optional: true @@ -7472,7 +7468,7 @@ packages: cpu: [wasm32] requiresBuild: true dependencies: - '@napi-rs/wasm-runtime': 0.2.10 + '@napi-rs/wasm-runtime': 0.2.12 dev: true optional: true @@ -8535,14 +8531,6 @@ packages: /@tybys/wasm-util@0.10.0: resolution: {integrity: sha512-VyyPYFlOMNylG45GoAe0xDoLwWuowvf92F9kySqzYh8vmYm7D2u4iUJKa1tOUpS70Ku13ASrOkS4ScXFsTaCNQ==} requiresBuild: true - dependencies: - tslib: 2.8.1 - dev: false - optional: true - - /@tybys/wasm-util@0.9.0: - resolution: {integrity: sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==} - requiresBuild: true dependencies: tslib: 2.8.1 optional: true From b72e855a41adb1d7ef0c6d014bd4ebd34c3d189f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E5=B9=B3?= Date: Wed, 30 Jul 2025 10:33:04 +0800 Subject: [PATCH 2/2] chore packages/preset-bundler/src/features/transformImport/transformImport.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../src/features/transformImport/transformImport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/preset-bundler/src/features/transformImport/transformImport.ts b/packages/preset-bundler/src/features/transformImport/transformImport.ts index 6db8d2f..5c8118d 100644 --- a/packages/preset-bundler/src/features/transformImport/transformImport.ts +++ b/packages/preset-bundler/src/features/transformImport/transformImport.ts @@ -63,7 +63,7 @@ export default (api: IApi) => { }), ) .describe( - '转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 babel-plugin-impor', + '转换 import 的路径,可以用于模块化引用三方包的子路径,能力类似于 babel-plugin-import', ) }, },