Combine ASP.NET MVC4 bundling and require.js javascript module dependency

asp.net-mvc-4requirejs

Is there a way to use the bundle functionality of ASP.NET MVC4 and the JavaScript module dependency feature of require.js

I want to load all my modules with ASP.NET MVC4 bundle features and use require.js to organize the relationships between them.

The problem is that require.js doesn't find the needed dependencies while all the modules are loaded via bundles.

I don't want require.js to go and try to load files asynchronous I just want it to use already loaded modules via bundles.

What should the main file look like in this case.

I Have the following structure in _Layout.chtml

@Scripts.Render("~/bundles/jquery",
                "~/bundles/jqueryval",
                "~/bundles/jslibs",
                "~/Scripts/require.js",
                "~/bundles/tjProductivity",
                "~/Scripts/tjpApp/main.js"
                )

@RenderSection("scripts", required: false)

And then in each scripts section I want to load all modules that will be used for that page via Bundle.config but let require.js manage dependencies between them.

Best Answer

It's possible, use almond.js, from the creator of RequireJS.

The only shortcoming is that you have to always add the module names on your modules...

Related Topic