Angular2中静态文件的默认路径是什么?

问题描述:

我目前正在从事一个小型Angular2项目.在我的情况下,我必须将一些请求(例如"/faq","/aboutus")重新路由回我的旧后端服务器,以获取一些服务器端呈现的百里香模板.因此,我正在使用内置代理重新路由到我的后端服务器.遗憾的是,出于某些奇怪的原因,它存储 html 文件而没有任何脚本样式图像. (我使用angular-cli创建了我的项目结构)

I'm currently working on a small Angular2 project. In my case i have to reroute some of the requests (like "/faq", "/aboutus") back to my old backend server to get some server side rendered thymeleaf templates. Therefore i'm using the built in proxy to reroute to my backende server. Sadly for some weird reason it only servers the html files without any scripts and styles or images. (i used the angular-cli to create my project structure)

这就是为什么我想将这些静态文件添加到我的angular2文件夹,但是我找不到正确的位置来使它可用于我的应用程序. 还有人知道如何正确地将这些文件放置在项目结构中吗?

Thats why i wanted to add these static files into my angular2 folder but i can't find the correct place to make it available to my application. Does anyone else know how to correctly place these file inside the project structure ?

在此先感谢您的帮助

根据当前 angular-cli自述文件(v1.0.1):

According to the current angular-cli readme (v1.0.1):

在构建项目时,可以使用angular-cli.json中的assets数组列出要按原样复制的文件或文件夹:

You use the assets array in angular-cli.json to list files or folders you want to copy as-is when building your project:

"assets": [
  "assets",
  "favicon.ico"
]

默认情况下,为此配置了assets文件夹,因此您可以将文件放入类似的结构中

By default the assets folder is configured for this, so you can place your files into a structure like

├── src
.   ├── assets
.   .   ├── file1.txt
.   .   ├── img
    .   │   └── image1.png
        └── css

并通过url路径/img/image1.png等提供它们.

and serve them from url path /img/image1.png etc.

如果您对默认选项不满意,请将您选择的文件夹名称添加到angular-cli.json,即

If you're not happy with the default option, add a folder name of your choice to angular-cli.json, i.e.

"assets": [
  "static",
  ...
]

为文件创建./src/static/文件夹,并与默认文件夹类似地提供服务.

Create the ./src/static/ folder for your files and serve analogously to the default.