Can system.js replace require.js

做~自己de王妃 提交于 2019-12-21 03:42:55

问题


I'm using requirejs in a large project. This project will soon be upgraded to angular2.

Angular2 uses system.js, so I'm thinking of switching to system.js too. Should I be able to remove the reference to the requirejs library and include system.js instead and expect it to work, or is there something I don't understand here?

I tried by just removing the require.js file and adding the system.js file instead, but I get error messages saying define is not defined. Can you help? Will I need require.js in addition to system.js?


回答1:


I just switched to system.js too. You need to replace your require.js with system.js and add simple script tag. So it should look like this:

<script src="~/lib/system.js/dist/system.js" type="text/javascript"></script>
<script>  
    // set our baseURL reference path
    System.config({
        baseURL: '/app'
    });
    System.import('startup.js');
</script>



回答2:


in addition to above steps set

System.defaultJSExtensions = true;

by default systemjs is not adding extension .js



来源:https://stackoverflow.com/questions/33332911/can-system-js-replace-require-js

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