-
Couldn't load subscription status.
- Fork 99
Closed
Labels
Milestone
Description
Problem
ref issue: #2004
antd umd 资产会依赖如下类型的 external,以 dayjs 为例:
function externalDayjs(config) {
const newConfig = { ...config }; // Shallow copy for safety
newConfig.externals.dayjs = {
root: 'dayjs',
commonjs2: 'dayjs',
commonjs: 'dayjs',
amd: 'dayjs',
};
return newConfig;
}这里会依赖 amd 的 external 产物,BTW,umd 产物在输出的时候会包装 external 的输出,以目前 antd 的 产物为例子:
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"), require("react-dom"), require("dayjs"));
else if(typeof define === 'function' && define.amd)
define(["react", "react-dom", "dayjs"], factory);
else if(typeof exports === 'object')
exports["antd"] = factory(require("react"), require("react-dom"), require("dayjs"));
else
root["antd"] = factory(root["React"], root["ReactDOM"], root["dayjs"]);
})()可以看到在 umd 的 cjs 、amd、esm、browser 等多环境中,会注入对应格式的 external 导入代码,目前 utoo-pack 没有处理这块逻辑,因此这里同样需要支持。
Solution
webpack 提供了示例的 externals 配置用于 umd 产物(refer link: https://webpack.js.org/configuration/externals/#object):
在 utoo-pack 也可以提供同样的 externals 配置去适配 umd 的 external 生成代码:
"config": {
"externals": {
"react": {
"root": "React", // for window
"commonjs": "react", // for cjs
"amd": "react", // for amd
}
}
}Alternatives
No response
Importance
nice to have
Additional Information
No response
