1

I'm trying to load different javascript files based on which environment I'm using. I have created an Angular2 application, which lives inside a MVC app.

In my index.html (_layout.cshtml), I have the following scripts:

<script src="~/public/lib/js/vendors.min.js"></script> <!--bundled dependencies-->
@*<script src="~/public/dist/js/app.min.js"></script> <!--bundled source-->*@

<script src="~/system.dev.config.js"></script>    
<script>
    System.import('../public/dist/AppComponent/main.js').catch(function (err) { console.error(err); });
</script>

This code will load angular2 dependencies and start the application. I want to distinguish between development (when I'm developing on the application) and when it's online in production.

I want to distinguish, so I only load the following files:

Dev environment:

<script src="~/public/lib/js/vendors.min.js"></script> <!--bundled dependencies-->

<script src="~/system.dev.config.js"></script>    
<script>
    System.import('../public/dist/AppComponent/main.js').catch(function (err) { console.error(err); });
</script>

Prod environment:

<script src="~/public/lib/js/vendors.min.js"></script> <!--bundled dependencies-->
<script src="~/public/dist/js/app.min.js"></script> <!--bundled source-->

Is there any option, so when I am in debug mode it should use the dev scripts and the other way around when in release mode?

Thanks in advance.

1
  • How do you run it without any loader? Commented Nov 27, 2016 at 19:28

1 Answer 1

1

You can use

@{ 
    #if DEBUG
        <script src="~/public/lib/js/vendors.min.js"></script> <!--bundled dependencies-->

        <script src="~/system.dev.config.js"></script>    
        <script>
            System.import('../public/dist/AppComponent/main.js').catch(function (err) { console.error(err); });
        </script>
    #else
        <script src="~/public/lib/js/vendors.min.js"></script> <!--bundled dependencies-->
        <script src="~/public/dist/js/app.min.js"></script> <!--bundled source-->
    #endif
}

I hope I have helped

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.