如何从"ng serve"服务静态目录 [英] How to serve static directory from "ng serve"
问题描述
我能问一下webpack开发服务器配置是否有类似的配置吗?
Can I ask if there are any similar config for webpack dev server config like this:
devServer : {
historyApiFallback : true,
stats : 'minimal',
contentBase: helpers.root('../src/static'),
}
我想从静态目录中提供静态文件,例如webpack开发服务器如何提供文件. 谢谢
I want to serve static files from static directory like how the webpack dev server is serving files. Thanks
推荐答案
是的.
在Angular应用程序的根目录中查找名为angular.json
的文件.有一个名为资产"的条目.在此处添加您的静态目录.它们下面的所有内容都将直接通过ng serve
提供.并且当您上线时,所有这些文件都将被复制到/dist目录,因此它们也将在生产环境中提供.
Look in the root of your Angular app for a file called angular.json
. There's an entry called "assets". Add your static directories here. Anything under them will be served directly via ng serve
. And when you go live, all of these files will be copied to the /dist directory so they'll be served in a production environment also.
"projects": {
"YourCoolProject": {
"root": "",
...
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
...
"assets": [
"src/assets",
"myOtherStaticFiles" /* <-- Add *your* directory(s) here */
],
"styles": [
...
p.s.是的,我知道您不能真正评论JSON.休息一下.
p.s. Yes, I know you can't really comment JSON. Give me a break.
这篇关于如何从"ng serve"服务静态目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!