使用Angular-CLI build复制一个文件/目录

Using Angular-CLI build to copy a file / directory

有没有办法让 angular-cli 的 ng buil --prod 命令也将 file/directory 复制到 dist 文件夹?

我的项目在根目录下包含一个 "server" 文件夹和一个 "config.js" 文件,我需要将它们复制到 "dist" 以便在构建时不需要记得复制那些目录

在您的 angular-cli.json 资产对象上添加您想要包含的文件夹,例如:

注意:对于 Angular 9,这应该放在 angular.json 文件中

"assets": [
    "assets",
    "favicon.ico",
    "META-INF",
    "WEB-INF"
  ]

对于那些想要复制 src 文件夹之外的文件的人:

在下面的示例中,我将所有文件从 myfolder 复制到根 dist 文件夹。

在angular-cli.json文件中(第3行):

"assets": [
   { "glob": "**/*", "input": "./assets/", "output": "./assets/" },
   { "glob": "favicon.ico", "input": "./", "output": "./" },
   { "glob": "**/*", "input": "../myfolder", "output": "./" }
],

Angular-cli.json Documentation here

来源Link

对于 ng build 使用 "postbuild" 命令复制 folder/files

更新package.json文件

来自

"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
....

},

"scripts": {
   "ng": "ng",
   "start": "ng serve",
   "build": "ng build && npm run postbuild",
   "postbuild":"xcopy /s \".\/dist\angular-material-bottom-sheet-app\" \".\/mydistapp\dist\" \/Y",
   "test": "ng test",
   "lint": "ng lint",
   "e2e": "ng e2e"
},

查看完整的详细信息here