Empty object require angular browserify

无人久伴 提交于 2019-12-05 12:24:16

Angular 1 doesn't support CommonJS modules, so it 'exports' an empty object.

Instead, just require it (without assigning the result):

require('angular')

This will attach angular to the global object.

UPDATE: As of Angular 1.3.14, require('angular') now returns the angular object.

You could also try browserify-shim to link the angular object to module.exports.

npm install -save-dev browserify-shim

I managed to get angular working with the following configuration in package.json:

{
    "browser": {
        "angular": "./node_modules/angular/angular.js"
    },
    "browserify-shim": {
        "angular": "angular"
    },
    "browserify": {
        "transform": [ "browserify-shim" ]
    }
}

This gets around the issue of making angular a global object, also. It (the angular variable) may stay an object stored in a global variable of the same name, but the reference will always be correct if someone overwrites the global variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!