@ucloud-fe/mod
v1.2.1
Published
A module loader support umd and own md
Downloads
154
Readme
MOD
安装
npm install @ucloud-fe/mod
引用
import mod from '@ucloud-fe/mod';
// 导入 amd 支持
import amdResolver from '@ucloud-fe/mod/lib/resolver/amd';
// 注册模块类型解析器
mod.registerModuleResolver(amdResolver);
使用
// 添加模块配置
mod.config({
modules: {
react: {
type: 'amd',
js: 'https://cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js'
},
'react-dom': {
type: 'amd',
js: 'https://cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js',
dep: 'react'
}
}
});
(async () => {
// 加载模块
const [React, ReactDOM] = await mod.import(['react', 'react-dom']);
// 使用模块
ReactDOM.render(React.createElement('button', {}, 'test'), document.getElementById('app'));
})();