按文件夹自定义TypeScript编译选项(Angular CLI+Fuse Theme场景)
Absolutely, you can make this work! Angular CLI supports multiple TypeScript configuration files, which lets you apply different compile options to specific parts of your codebase without modifying the uneditable Fuse theme files. Here's how to set it up:
1. Create a dedicated TS config for Fuse
First, make a new config file in your project root called tsconfig.fuse.json. This will extend your main TS config but override the strict settings that clash with Fuse:
{ "extends": "./tsconfig.json", "compilerOptions": { // Disable the strict settings that break Fuse—tweak these based on your actual errors "strict": false, // Or disable specific strict sub-options instead of turning off all strict mode: // "strictNullChecks": false, // "strictPropertyInitialization": false }, "include": [ "src/@fuse/**/*" ], "exclude": [] }
2. Update your angular.json configuration
Open angular.json and find the architect -> build and architect -> serve sections for your project. Update the options in both to use the dual config setup:
For the build target:
"options": { "tsConfig": "tsconfig.json", // Add the Fuse-specific config as an additional TS config "additionalTsConfigs": ["tsconfig.fuse.json"], // Exclude @fuse from the main config to avoid duplicate processing "exclude": ["src/@fuse/**/*"] }
For the serve target (so dev mode works too):
"options": { "browserTarget": "your-project-name:build", "tsConfig": "tsconfig.json", "additionalTsConfigs": ["tsconfig.fuse.json"], "exclude": ["src/@fuse/**/*"] }
(Make sure to replace your-project-name with the actual name of your project in angular.json.)
3. Test it out
Run ng build or ng serve like you normally would. Now:
- Your app code (src/app, src/assets, etc.) will use your strict
tsconfig.jsonsettings - The uneditable
src/@fusefiles will compile using the relaxed settings intsconfig.fuse.json, no more strict-mode errors from the theme!
Quick note for older Angular versions
If additionalTsConfigs isn't available in your Angular CLI version (it's supported in Angular 10+), you can work around it by excluding src/@fuse from your main tsconfig.json, then adding the Fuse files directly in the files array of your angular.json build options, paired with the tsConfig pointing to tsconfig.fuse.json. But the additionalTsConfigs method is cleaner if you can use it.
内容的提问来源于stack exchange,提问作者Romain Deneau

