Angular2-自定义CSS/JS文件的文件夹? [英] Angular2 - What folder for custom CSS / JS files?

查看:52
本文介绍了Angular2-自定义CSS/JS文件的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的angular2应用程序中包含一组CSS和JS文件.

什么是正确的文件夹才能将其包含在我进行构建时?

我是否必须将它们放在 SRC \ Assets SRC \ myFolder 下?

一旦定义了它,如何将它们包含在我的app.component.html中,以及如何正确配置< base href ="/"> ?

感谢支持

解决方案

如果您使用Angular CLI,则可以将它们放在任何地方,但是我建议在一个合理的位置上放置在src/assets文件夹中.

从此处在angular.cli.json文件中添加js和css文件的条目.

apps节点中每个对象/app下都有一个scripts数组和一个styles数组.

寻找类似...

  apps:[{..."styles":["assets/styles/myCustomStyles.css"],脚本":["assets/js/dragevents.js"]}] 

如果正确完成,cli将在构建时自动将它们添加到您的索引中.

I have to include a set of CSS and JS files in my angular2 application.

What is the correct folder in order to have them included when I do the build?

Should I have to put them inside SRC\Assets or under SRC\myFolder ?

Once defined it, how do I have to include them inside my app.component.html and how to configure <base href="/"> properly?

Thanks to support

解决方案

If your using the Angular CLI then you can put them anywhere, but I would suggest in a logical place that makes sense in your src/assets folder.

From there add entries for the js and css files in your angular.cli.json file.

there is a scripts array and a styles array under each object/app in the apps node.

look for something like ...

apps: [
 {
   ...
   "styles": [ "assets/styles/myCustomStyles.css" ],
   "scripts": [ "assets/js/dragevents.js" ]
 }
]

If done correctly the cli will automatically add them to your index when it builds.

这篇关于Angular2-自定义CSS/JS文件的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆