Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Angular-CLI build to copy a file / directory

Tags:

angular-cli

Is there a way to make angular-cli's ng buil --prod command to also copy a file/directory to the dist folder?

My project includes a "server" folder, and a "config.js" file at root, and I need them to be copied to "dist" such that when building, I don't need to remember to copy those directories

like image 919
Amit Avatar asked Nov 12 '16 20:11

Amit


3 Answers

For those wanting to copy files outside the src folder:

In example below I am copying all files from myfolder to the root dist folder.

In the angular-cli.json file (3rd line):

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

Angular-cli.json Documentation here

like image 181
Stephane Avatar answered Nov 08 '22 03:11

Stephane


On your angular-cli.json on assets object add the folders you want to include like:

Note : For Angular 9, this should be placed on angular.json file

"assets": [
    "assets",
    "favicon.ico",
    "META-INF",
    "WEB-INF"
  ]
like image 29
Lenin Lambis Avatar answered Nov 08 '22 01:11

Lenin Lambis


Source Link

For ng build use the "postbuild" command to copy folder/files

Update the package.json file

From

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

},

To

"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"
},

Check complete details here

like image 1
Code Spy Avatar answered Nov 08 '22 01:11

Code Spy