8000 如何用CMD模块定义规范声明一个组件 · Issue #13 · malaxiannv/blog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
如何用CMD模块定义规范声明一个组件 #13
Open
@malaxiannv

Description

@malaxiannv

https://github.com/hehongwei44/my-blog/wiki/CMD%E6%A8%A1%E5%9D%97%E5%AE%9A%E4%B9%89%E8%A7%84%E8%8C%83

/**
 * 定义声明单个组件,例如 'rax-text'
 * @param {string} componentName 定义的组件名
 * @param {string} moduleName generateIndexFile文件中导出的模块名
 * @param {string} requireModule 依赖的组件名
 */
const defineComponent = (componentName, moduleName, requireModule) => {
  return ` 
     define('${componentName}', [], function(require, exports, module){ ;(function() { var fn = function(){ var {${moduleName}} = require('${requireModule}'); return ${moduleName};}
     if (typeof exports === "object" && typeof module !== "undefined") { module.exports = fn(); } 
     else if (typeof define === "function") {define('${componentName}', function(require, exports, module){ module.exports = fn(); });} 
     else { var root; if (typeof window !== "undefined") { root = window; } 
     else if (typeof self !== "undefined") { root = self; } 
     else if (typeof global !== "undefined") {root = global; } else { root = this; } root['${componentName}'] = fn(); } })(); });
    `;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0