简体   繁体   English

资产未从项目复制到 Angular 7 库中的 dist 文件夹

[英]Assets not copied from project to dist folder in Angular 7 library

i've generated new library via Angular CLI v7我通过 Angular CLI v7 生成了新库

ng generate library library-name

After that, i've created folder assets in src folder.之后,我在 src 文件夹中创建了文件夹资产。 So my folder structure is所以我的文件夹结构是

| - src
| - - lib
| - - - assets

My problem is, that after我的问题是,在那之后

ng build --project=library-name

are assets missing in my dist folder.我的 dist 文件夹中缺少资产。 All modules, components, styles etc. are exported in dist folder.所有模块、组件、样式等都导出到 dist 文件夹中。 But if i create another directory in this hierarchy, directory is not exported to dist at all.但是,如果我在此层次结构中创建另一个目录,则目录根本不会导出到 dist。

How can i force assets to be exported in dist folder after build ?如何在构建后强制将资产导出到 dist 文件夹中?

Thanks谢谢

This is not currently supported by the CLI, you can read more in the GitHub issue here: https://github.com/angular/angular-cli/issues/11071#issuecomment-395096971 CLI 当前不支持此功能,您可以在此处的 GitHub 问题中阅读更多内容: https : //github.com/angular/angular-cli/issues/11071#issuecomment-395096971

An easy workaround as suggested is to manually cp -r path/to/lib/assets list/path/to/lib the assets after you build the library.建议的一个简单解决方法是在构建库后手动cp -r path/to/lib/assets list/path/to/lib资产。 You could use a post build script in your package.json for this.为此,您可以在 package.json 中使用后期构建脚本。

This has been fixed since approx.这已被修复,因为大约。 Jan 2020 2020 年 1 月

src 源文件

tldr; tldr;

in ng-package.json or equiv.ng-package.json或等效文件中。 you can include what you want bundled:你可以包括你想要捆绑的东西:

{
  ...,
  "assets": [
    "./assets",
    "CHANGELOG.md",
    "./styles/**/*.theme.scss"
  ],
  ...
}

main project glob主要项目glob

You'll also want to be sure to include the glob in your angular.json that's importing the packaged lib.您还需要确保在导入打包库的 angular.json 中包含 glob。

condensed example:浓缩的例子:

"projects": { "hello-world": {
    "projectType": "application",
    "architect": { "build": { "options": {
      "assets": [
        ...,
        {
          "glob": "**/*",
          "input": "node_modules/your/library",
          "output": "./assets"
        }
      ]
} } } } }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM