Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yog2 污染UMD的大BUG #163

Open
jackiealex opened this issue Mar 29, 2017 · 2 comments
Open

yog2 污染UMD的大BUG #163

jackiealex opened this issue Mar 29, 2017 · 2 comments

Comments

@jackiealex
Copy link

jackiealex commented Mar 29, 2017

这个文件——yog2-kernel/plugins/isomorphic/index.js中有一行(第12行)代码这么写的:

global.define = function (id, factory) {
        frontendFactoryCache['frontend_' + id] = factory;
  };

这个挂载在global上的define,项目的任何地方都可以访问,当我在nodejs中引入一个umd,结果就跪了

    // RequireJS && SeaJS
    if (typeof define === 'function') {
        define(function() {
            return template;
        });

    // NodeJS
    } else if (typeof exports !== 'undefined') {
        module.exports = template;
    } else {
        this.template = template;
    }

在nodejs,程序直接命中第一个判断,使用了define 导出对象template,实际上导出的是module.exports = {}(默认)

于是我就只能:

// RequireJS && SeaJS
if (typeof define === 'function') {
    define(function() {
        return template;
    });
} 

// NodeJS
if (typeof exports !== 'undefined') {
    module.exports = template;
} 

// in no define env or browser
if (typeof window == 'object' && typeof define !='function') {
    this.template = template;
}

求大神修复

@hefangshi
Copy link
Member

这种情况只能在插件中关闭isomorphic,方法是新建 conf/plugins/isomorphic.js 文件,内容编写为

module.exports.isomorphic = {
    YOG_DISABLE: true
}

@jackiealex
Copy link
Author

这种设计隐藏的比较深,谁也不知道在使用yog2 的默认情况下,umd就被污染了,而且所有的umd都将无法导出模块,虽然可以关闭,但是开发者在使用时,不会知道这种情况,就好比大马路上的一个坑,是个陷阱,建议不要污染define

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants