简体   繁体   中英

How to add own css and js files to the build of Angular 2 App?

Angular 2 automatically adds link to styles.css to the head and some scripts to the end of body of index.html.

For example:

<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="styles.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>

Where I can configure Angular to add also my own .css and .js files to the build? PS I'm using CLI

Open your angular-cli.json file and find assets array. Push the links inside of the files you want the build process to include.

"assets": [
    "assets",
    "favicon.ico",
    "styles.css",
    "d3.js",
],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM