You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 4使用--prod构建时如何排除文件夹、assets目录及JSON数据

Excluding Folders, Assets, and JSON Files in Angular 4 Production Builds (--prod)

Hey there, let's walk through exactly how to exclude specific content when running ng build --prod in your Angular 4 project. Angular 4 relies on the angular-cli.json file (not the newer angular.json from later Angular versions) for build configuration tweaks, so we'll focus on editing that file here.

1. Excluding Custom Standalone Folders

If you have a standalone folder (like a temp directory or unused utility folder) that you don't want included in your production build, add its path to the exclude array in your angular-cli.json:

"apps": [
  {
    // ... other existing config settings
    "exclude": [
      "temp-files/**/*",
      "unused-utils/**/*"
    ]
  }
]
  • The **/* wildcard ensures we exclude all files and subfolders inside the target directory, not just the folder itself.

2. Excluding Specific Content from the Assets Folder

By default, Angular copies everything in your assets folder to the dist directory during a build. To exclude specific files or subfolders within assets, you'll need to replace the simple string path in the assets array with a detailed object configuration:

Default Assets Setup (Before Exclusions):

"assets": [
  "assets",
  "favicon.ico"
]

Modified Assets Setup (With Exclusions):

"assets": [
  "favicon.ico",
  {
    "glob": "**/*",
    "input": "./assets/",
    "output": "./assets/",
    "ignore": [
      "old-images/**/*",
      "unused-config.json"
    ]
  }
]
  • glob: Matches all files and subfolders in the specified input directory
  • input: The source assets directory (relative to your project root)
  • output: Where the included assets will be placed in the final dist folder
  • ignore: The list of paths (relative to input) you want to exclude from the build

3. Excluding JSON Files

How you exclude JSON files depends on their location:

  • JSON files outside the assets folder: Add their direct path (or wildcard paths) to the exclude array in angular-cli.json:
    "exclude": [
      "src/legacy-data/*.json",
      "src/temp/*.json"
    ]
    
  • JSON files inside the assets folder: Use the ignore array in the assets configuration we covered in section 2.

Quick Pro Tip

After modifying your angular-cli.json, clear the build cache before running your production build to ensure the exclusions take effect properly:

ng clean
ng build --prod

Hope this helps you tailor your production build exactly how you need it!

内容的提问来源于stack exchange,提问作者Gaurav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:08:45