brijmcq
brijmcq

Reputation: 3418

Using cdn instead of serving locally when using ng build --prod in Angular CLI

I am serving the Bootstrap framework locally for my development. Currently, the way I do it is adding my bootstrap in angular-cli.json like this

 "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "styles.css"
      ],

By the way, I use

ng build --prod

when making my production build.

Is there a quick and nice trick to make use of CDN instead when I build it for production? Though I can achieve this by just manually add a bootstrap cdn in my index.html and delete the one in angular-cli.json. I am just wondering how you guys do it.

Upvotes: 3

Views: 3296

Answers (1)

Adam
Adam

Reputation: 1975

Not sure if this is what you are after, but if you want to serve assets off a cdn (as in, bundle.css, bundle.js, vendor.js)

You can run ng build --prod --deploy-url "https://cdn.yoursite.com/"

Then in your index you'll see:

<script type="text/javascript" src="https://cdn.yoursite.com/main.90c90d8887d1e50f79fb.bundle.js">

You will have to either upload the files during deployment or point your cdn at your app.

Bootstrap will be included in the bundle, and then served off your own cdn

Upvotes: 7

Related Questions