5

I would like to know if there is a way to configure the scripts section of the angular.json file depending on the environment.

I would like to include a specific script(Myscript.js) only when I'm in the production environment.

"scripts": [
          "./node_modules/jquery/dist/jquery.min.js",
          "./node_modules/slick-carousel/slick/slick.min.js",
          "./src/assets/scripts/Myscript.js"
        ]

I don't find anything in the doc about that. Is it possible?

1
  • Can you use that variable in your index.html and put script conditionally? Commented Dec 28, 2018 at 9:05

1 Answer 1

7

You can add the scripts array to your production configuration inside the angular.json. This is located in

projects->{projectName}->architect->build->configurations->production

"projects": {
  {projectName}: {
    "architect": {
      "build": {
        "configurations": {
          "production": {
            "scripts": [
              "./node_modules/jquery/dist/jquery.min.js",
              "./node_modules/slick-carousel/slick/slick.min.js",
              "./src/assets/scripts/Myscript.js"
            ]
          }
        }
      }
    }
  }
}

This however does not look if the environment variable is set to true, so if you have more configurations that need this, you can obviously add it there as well.

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

2 Comments

seems to be exactly what I wanted to do! But I don't get the point with the extension you talked about. I can create a sub configuration?
@bAN I've removed that part. Can't find it anywhere in the documentation anymore, nor in the JSON schematics of the angular file. Soo, I guess I thought wrong :)

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.