문제

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