我有一个旧的web应用程序,它已经使用了ASP.Net MVC的捆绑和缩小。
现在,我开始使用requirejs,我遇到了一个问题!我怎样才能引用requirejs中的包文件呢?
我知道还有另一个类似的问题,但它没有回答我的问题!
How to reference the bundled js files (asp.net mvc4) in Require.js?
发布于 2014-02-21 05:55:05
我希望我能正确理解你的问题。
如果您的捆绑包包含requireJS modules,并且您正在将其加载到页面上,那么您仍然可以调用这些modules,只要您像下面这样定义了它们:
假设您现有的包是这样呈现的:
@Scripts.Render("~/bundles/aCustomBundle")该捆绑包包含jQuery、React和一个aLibrary模块。在该捆绑包中,aLibrary定义如下。
// Define custom modules
define('aLibrary', [], function() {
return {
aFunction: function() {
console.log('a function within a library');
}
}
});在您的页面中,可以调用该模块并定义第三方库,如下所示。
<script>
// Third party libraries
define('jquery', [], function () { return jQuery; });
define('react', [], function () { return React; });
// Use the libs from the bundle
require(['aLibrary', 'jquery', 'react'], function(a, j, r) {
// Execute the function from the aLibrary
a.aFunction();
});
</script>https://stackoverflow.com/questions/21838793
复制相似问题