【问题标题】:Angular 6 universal, .net template , unable to publish due to uglifyjs-webpack-pluginAngular 6 通用,.net 模板,由于 uglifyjs-webpack-plugin 无法发布
【发布时间】:2018-06-21 08:42:47
【问题描述】:

我正在使用带有 .net 模板的 Angular 6 通用版,无法发布该网站。我收到以下错误:

C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(140,5):错误 MSB3030:无法复制文件“C :\项目\藏匿\ serversiderendering \ serverSideRendering \ ClientApp \ node_modules.cache \ uglifyjs-的WebPack-插件\内容-V2 \ SHA512 \ 12 \ 98 \ ca644f17078ac9e4c0fcda9c49f1ce74cd50192b7a404d45d26adabcc8f8fa22ca38476a913d2b79930a104b1d8fe9d2400a1dbc65e6951943067e92ebc5" ,因为它没有被发现。 [C:\projects\stash\serversiderendering\serverSideRendering\serverSideRendering.csproj]

在.cache 文件夹中复制uglifyjs-webpack-plugin 的东西。

我浏览了如何启用通用的教程:Use the Angular project template with ASP.NET Core。该模板带有 Angular 5 我将 Angular 和 cli 更新为 6,所以我不得不做一些更改:

我的 angular.json 文件看起来像:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "serverSideRendering": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "progress": true,
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/server",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          },
          "configurations": {
            "production": {
              "browserTarget": "serverSideRendering:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "serverSideRendering:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "assets": [
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "serverSideRendering-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "serverSideRendering:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "ssr": {
      "root": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/server",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          },  "configurations": {
            "dev": {
                "sourceMap": false
            },
            "production": {
                "optimization": true,
                "outputHashing": "none",
                "sourceMap": false,
                "namedChunks": false,
                "extractLicenses": true,
                "vendorChunk": false,
                "fileReplacements": [
                    {
                        "replace": "src/environments/environment.ts",
                        "with": "src/environments/environment.prod.ts"
                    }
                ]
            }
        }
        }
      }
    }
  },
  "defaultProject": "serverSideRendering",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

我的 package.json 看起来像:

{
  "name": "serverSideRendering",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build:ssr": "npm run build -- --project=ssr",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.5",
    "@angular/cdk": "6.0.1",
    "@angular/common": "6.0.1",
    "@angular/compiler": "6.0.1",
    "@angular/core": "6.0.1",
    "@angular/forms": "6.0.1",
    "@angular/http": "6.0.1",
    "@angular/platform-browser": "6.0.1",
    "@angular/platform-browser-dynamic": "6.0.1",
    "@angular/platform-server": "6.0.1",
    "@angular/router": "6.0.1",
    "@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
    "aspnet-prerendering": "^3.0.1",
    "bootstrap": "^3.3.7",
    "core-js": "2.5.5",
    "rxjs": "6.1.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.6.1",
    "@angular/cli": "6.0.1",
    "@angular/compiler-cli": "6.0.1",
    "@angular/language-service": "6.0.1",
    "@angularclass/hmr": "latest",
    "@types/jasmine": "^2.8.6",
    "@types/jasminewd2": "^2.0.3",
    "@types/mongodb": "^3.0.5",
    "@types/node": "~6.0.60",
    "codelyzer": "latest",
    "jasmine": "latest",
    "jasmine-spec-reporter": "latest",
    "karma": "latest",
    "karma-chrome-launcher": "latest",
    "karma-coverage-istanbul-reporter": "latest",
    "karma-jasmine": "latest",
    "karma-jasmine-html-reporter": "latest",
    "mongodb": "3.1.0-beta4",
    "protractor": "latest",
    "ts-node": "latest",
    "tslint": "latest",
    "typescript": ">=2.7.2 and <2.8.0",
    "uglifyjs-webpack-plugin": "^1.2.5"
  },
  "optionalDependencies": {
    "node-sass": "^4.9.0"
  }
}

【问题讨论】:

  • 我有完全相同的问题,我无法弄清楚。我希望有人能尽快找到答案。
  • @DavidPine 我发布了我的修复 - 希望它有所帮助。

标签: angular webpack angular-universal uglifyjs-webpack-plugin


【解决方案1】:

我可以通过在 csproj 任务 PublishRunWebpack 中排除 .cache 文件夹来解决此问题,如下所示:

<PropertyGroup>
    ...
    <SpaRoot>Client</SpaRoot>
    ...
</PropertyGroup>

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
  <DistFiles Include="$(SpaRoot)\dist\**" />
  <DistFiles Include="$(SpaRoot)\node_modules\**; $(SpaRoot)\dist-server\**" 
             Exclude="$(SpaRoot)\node_modules\.cache\**" 
             Condition="'$(UseServerSideRenderer)' == 'true'" />
  <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')"
                         Exclude="@(ResolvedFileToPublish)">
    <RelativePath>%(DistFiles.Identity)</RelativePath>
    <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
  </ResolvedFileToPublish>
</ItemGroup>

【讨论】:

  • 这解决了我的 uglify-js 和 SHA512 文件的路径太长问题 :)
  • @John 发布你的 package.json 并在生产环境中使用 yarn/npm 安装包是个好主意。使用 node_modules 发布非常慢。我们使用 CI/CD 并从 node_modules 切换到发布 package.json 将构建/部署时间减少了 15 分钟。
【解决方案2】:

我只能通过在angular.js 中关闭服务器端优化来解决我的问题

     "server": {
      "builder": "@angular-devkit/build-angular:server",
      "options": {
        "outputPath": "dist/server",
        "main": "src/main.server.ts",
        "tsConfig": "src/tsconfig.server.json",
        "optimization": false
      }
    }

【讨论】:

    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    相关资源
    最近更新 更多