Bundling and minifying modular JavaScript (RequireJS / AMD) with ASP.NET MVC

后端 未结 4 1338
轮回少年
轮回少年 2020-12-24 01:35

Does anyone have any experience with or know any good solutions for bundling and minifying modular JavaScript like RequireJS / AMD in an ASP.NET MVC project?

Is the

4条回答
  •  自闭症患者
    2020-12-24 02:32

    These are the steps to get RequireJS bundled with main.js. You can get down to one line in the tag. This does not address the issue with anonymous defines.

    HTML

    
        
        <%: System.Web.Optimization.Scripts.Render("~/bundles/scripts") %>
    
    

    BundleConfig.cs

    using System.Web;
    using System.Web.Optimization;
    
    public class BundleConfig
    {
        // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
                        "~/scripts/libs/require.js",
                        "~/scripts/main.js"));
       }
    }
    

    main.js must work without data-main (I needed to set baseUrl)

    require.config({
        baseUrl: "scripts"
    });
    

提交回复
热议问题