asp.net-mvc-4web-optimizationscriptbundle

ScriptBundle with additional attributes


public class BundleConfig
{
    // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/require").Include(
                        "~/Scripts/require.js"));
       ....

and in the _Layout.cshtml

@Scripts.Render("~/bundles/require")

it renders into (with EnableOptimizations = false):

<script src="/Scripts/require.js"></script>

but I want to add an attribute

<script src="/Scripts/require.js" data-main="/Scripts/main"></script>

how could I do that?


Solution

  • I've solved similar issue by configuring requirejs without data-main attribute. So, at first I had following code:

    <script src="app/rconfig.js"></script>
    <script src="plugin/requirejs/require.js" data-main="app/main.js"></script>
    

    Next, let's get rid from the data-main attribute:

    <script src="app/rconfig.js"></script>
    <script src="plugin/requirejs/require.js"></script>
    <script>
        require.config({
            baseUrl: "app"
        });
        require(['app/main.js']);
    </script>
    

    Next, I've put last 'script' content to the file:

    <script src="app/rconfig.js"></script>
    <script src="plugin/requirejs/require.js"></script>
    <script src="app/rdatamain.js"></script>
    

    At finish, I've put these three files to the bundle