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

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

问题描述

我正在编写一个与 NodeJs 应用程序一起运行的 Angular 应用程序.NodeJs 应用程序监视 Angular 应用程序文件夹中名为 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.

因为该应用程序在内存中提供,所以当图像添加到幻灯片时,它会发生 404 秒.我必须杀死 ng serve 并重新启动它才能加载图像.我希望看到图像实际加载到幻灯片中,而不必终止 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 配置中资产文件夹的一部分,它确实被复制了.只有在 ng serve 运行时将文件添加到此文件夹时,图像才会加载失败.

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 并编辑应用的 assets 属性.

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天全站免登陆