简体   繁体   English

在 /dist 文件夹中构建 Angular 资产

[英]Angular assets building in /dist folder

I am using the flag-icon-css package that supplies you a css "font" file and all SVGs of flags.我正在使用 flag-icon-css 包,它为您提供一个 css“字体”文件和所有标志的 SVG。 There was an issue with the package (4x3 flags not showing properly), so I pulled all of the files out of node_modules and fixed the issue.包存在问题(4x3 标志未正确显示),因此我从node_modules提取了所有文件并修复了该问题。

I now have all of the css and flag icons under the src/assets/fonts folder.我现在在src/assets/fonts文件夹下有所有的 css 和标志图标。 I updated my angular.json to reflect the changes and made sure the flag-icon-css folder in node_modules was deleted, but the flag icons are still saving in both the /dist and also assets/fonts folder.我更新了我的angular.json以反映更改,并确保该flag-icon-css文件夹node_modules已被删除,但旗上的图标都仍然保存/distassets/fonts文件夹中。

Here is what my angular.json was changed to:这是我的angular.json更改为:

  "styles": [
    "src/assets/fonts/flags/flag-icon.min.css",
    "src/styles.scss"
  ],
  "assets": [
    "src/favicon.png",
    "src/assets",
  ],

I even tried adding the full path: src/assets/fonts/flags/icons , but it still builds them directly into the dist folder.我什至尝试添加完整路径: src/assets/fonts/flags/icons ,但它仍然将它们直接构建到dist文件夹中。

All files added to "styles": [] are always moved to the top level of the root ' /dist ' when builded.添加到"styles": []所有文件在构建时总是移动到根 ' /dist ' 的顶层。 This is because they're global files.这是因为它们是全局文件。 More info here under "styles".更多信息在这里下的“风格”。

You have multiple options to solve your problem:您有多种选择来解决您的问题:

Remove the "src/assets/fonts/flags/flag-icon.min.css" from the "styles": [..] array."styles": [..]数组中删除 "src/assets/fonts/flags/flag-icon.min.css"。

Option 1.选项1。

Import it into your styles.scss like:将它导入你的styles.scss如:

@import('path/outside/assets/flag-icon.min.css')

Now they should be included in your /dist/styles.css after build.现在它们应该在构建后包含在您的/dist/styles.css If you keep the icons inside the assets folder they will be imported to the styles.css and /dist/assets/.. folder如果您将图标保留在assets 文件夹中,它们将被导入到styles.css/dist/assets/..文件夹中

Option 2选项 2

Import the icon set from your index.htmlindex.html导入图标集

<link href="assets/fonts/flags/flag-icon.min.css" rel="stylesheet">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 资产未复制到角度的dist文件夹中 - Assets not copied to the dist folder in angular Angular CLI资产文件夹未放入dist文件夹 - Angular CLI assets folder not going into dist folder Angular CLI 不会将资产文件夹复制到 dist - Angular CLI not copying assets folder to dist 构建角度应用程序,获取应用程序中使用的所有图像,在dist文件夹中的字体文件而不是常规资源文件夹? 为什么? - Building angular application, getting all the images used in application, font files in dist folder instead of regular assets folder? Why? Angular 6 CLI 不会将库的资产文件夹复制到 dist 文件夹中 - Angular 6 CLI does not copy library's assets folder into dist folder 资产未从项目复制到 Angular 7 库中的 dist 文件夹 - Assets not copied from project to dist folder in Angular 7 library Angular CLI Build prod命令未在dist文件夹中构建组件 - Angular CLI Build prod command not building components in dist folder angular 10:图像 url 在 `Ng build` 后直接在`dist` 文件夹和`dist-&gt;assets` 下列出 - angular 10: image url given from assets after `Ng build` is listing directly under `dist` folder and `dist->assets` Angular CLI:dist中的资产,但不是build - Angular CLI: Assets in dist, but not build 使用go服务一个角度dist文件夹 - Serving an angular dist folder with go
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM