简体   繁体   English

Angular CLI 不会将资产文件夹复制到 dist

[英]Angular CLI not copying assets folder to dist

I have an app that was in Angular 4 with a custom build system.我有一个使用自定义构建系统的 Angular 4 应用程序。 I am trying to convert it to Angular 6 using ng-cli .我正在尝试使用ng-cli将其转换为 Angular 6。 However, I am having trouble getting the ng build command to copy the src/assets folder to dist .但是,我无法使用ng build命令将src/assets文件夹复制到dist

This is the relevant part of my angular.json file:这是我的angular.json文件的相关部分:

"projects": {
  "client": {
    "root": "",
    "sourceRoot": "src",
    "projectType": "application",
    "prefix": "app",
    "schematics": {},
    "architect": {
      "build": {
        "builder": "@angular-devkit/build-angular:browser",
        "options": {
          "outputPath": "dist/client",
          "index": "src/index.html",
          "main": "src/main.ts",
          "polyfills": "src/polyfills.ts",
          "tsConfig": "src/tsconfig.app.json",
          "assets": [
            "src/assets"
          ],
          "styles": [
            "./node_modules/bootstrap/dist/css/bootstrap.min.css",
            "src/styles/styles.css"
          ],
          "scripts": [
            "./node_modules/jquery/dist/jquery.min.js",
            "./node_modules/bootstrap/dist/js/bootstrap.js"
          ]
        }
.
.
.
... rest of angular.json

and my assets folder is also not empty :我的资产文件夹也不为空

资产文件夹

I have a css file that references some of the files in assets/fonts/ , so the CLI just places those files in the root of the dist folder, instead of dist/assets and does not copy the other files.我有一个 css 文件,它引用了assets/fonts/一些文件,所以 CLI 只是将这些文件放在dist文件夹的根目录中,而不是dist/assets并且不复制其他文件。

Responding to answers here as well:在这里也回复答案:

It was "src/assets" originally.它最初是"src/assets" That didn't work.那没有用。 So I tried with "./src/assets" but that didn't work either.所以我尝试使用"./src/assets"但这也不起作用。

I had similar issue with an asp.net core and angular project and the below setup in angular.json worked:我在 asp.net core 和 angular 项目中遇到了类似的问题,angular.json 中的以下设置有效:

"assets": [
   {
    "glob":"**/*",
    "input":"src/assets/",
    "output":"assets/"
   }
 ],

remove the " . " in your path, it might solve your problem. 删除路径中的“ ”,可能会解决您的问题。 also make sure your sourceroot is set to src . 还要确保您的sourceroot设置为src like this "sourceRoot": "src" 像这样的"sourceRoot": "src"

 "assets": [
    "src/assets"
  ],

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

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