Exclude files from build in Angular 2

2019-04-04 16:42发布

问题:

How can I exclude files from the angular build using angular-cli. I just add the path to exclude in the tsconfig.json and tsconfig.app.json files but when I run ng serve, angular still trying to compile the files.

Any ideas?

回答1:

Using exclude property of tsconfig.json (at root level), i.e.:

{
   "exclude": [
       "node_modules",
       "**/*.spec.ts"
   ]
}


回答2:

You can use ng eject to get the webpack.config.js. You can modify this to your needs. However, you will not be able to use ng serve or ng build after that.

For using these commands again, you have to modify .angular-cli.json. Remove the property 'projects.ejected' or set it to false. How to undo Angular 2 Cli ng-eject



回答3:

I noticed if you put a . in front of the path it will work:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    ...
  },
  "exclude": [
    ...
    "./yourPathToExclude/**/*"
  ]
}