سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

If you don't like RenderFormat, you can change the DefaultTagFormat globally on the ScriptsHelper too, but this attribute would now show up everywhere you called Scripts.Render

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top