在资产动态添加时为其提供服务 [英] Serve assets as they are dynamically added

查看:59
本文介绍了在资产动态添加时为其提供服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可在NodeJs应用程序上运行的Angular应用程序. NodeJs应用程序监视Angular应用程序文件夹中一个名为Gallery的文件夹.这个想法是,当将图像添加到Gallery文件夹时,应将其添加到作为Angular应用程序一部分运行的图像幻灯片中.

I am writing an Angular application that runs along a NodeJs app. The NodeJs app watches a folder called gallery inside the Angular app folder. The idea is that when an image is added to the gallery folder, it should be added to an image slideshow running as part of the Angular app.

由于该应用程序已存储在内存中,因此当将图像添加到幻灯片时,它会显示404s.我必须终止ng serve并重新启动它才能加载图像.我希望看到图像实际上已加载到幻灯片中,而无需关闭服务并重新启动.

Because the app is served in memory, when the image is added to the slideshow, it 404s. I have to kill ng serve and restart it in order for the image to load. I'd like to see the image actually load into the slideshow without me having to kill ng serve and restart it.

是否有解决方法?

gallery文件夹是cli配置中Assets文件夹的一部分,并且确实被复制了.只有在ng服务运行时将文件添加到此文件夹中时,图像才会加载失败.

The gallery folder is part of the assets folder in the cli config and it does get copied over. It's only when adding files to this folder while the ng serve is running that the image fails to load.

谢谢!

推荐答案

打开angular-cli.json并编辑应用程序的资产属性.

Open angular-cli.json and edit the assets properties of your app.

 "assets": [
    "assets",
    "favicon.ico",
    { "glob": "**/*", "input": "./assets/gallery", "output": "./assets/gallery" }
  ],

Webpack仍将需要重新编译这些资产,但至少您不必启动和停止该应用程序.

Webpack will still need to recompile these assets, but at least you don't have to start and stop the app.

Angular CLI文档

这篇关于在资产动态添加时为其提供服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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