Angular2 中静态文件的默认路径是什么? [英] Whats the default path for static files in Angular2?

查看:34
本文介绍了Angular2 中静态文件的默认路径是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个小型 Angular2 项目.就我而言,我必须将一些请求(如/faq"、/aboutus")重新路由回我的旧后端服务器,以获得一些服务器端呈现的 thymeleaf 模板.因此,我使用内置代理重新路由到我的后端服务器.遗憾的是,由于某种奇怪的原因,它服务器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.

这篇关于Angular2 中静态文件的默认路径是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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