要在Angular 7中启用树摇(tree-shaking)但不进行代码压缩,你可以按照以下步骤进行设置:
tsconfig.json
文件。compilerOptions
中的"removeComments"
选项设置为true
,这将删除所有注释。"sourceMap"
选项为true
,以便在调试时可以使用源映射。"target"
选项设置为es2015
,这将生成ES2015版本的JavaScript代码。"module"
选项设置为es2015
,以便在生成的代码中使用ES模块系统。"downlevelIteration"
选项设置为true
,以便在生成的代码中正确支持迭代器和生成器。"noEmitHelpers"
选项设置为true
,以便在生成的代码中不包含辅助函数。"importHelpers"
选项设置为true
,以便在生成的代码中使用辅助函数的外部模块。"angularCompilerOptions"
中的"enableIvy"
选项设置为false
,以便使用Angular的旧编译器。tsconfig.json
文件。这样设置后,当你构建项目时,将启用树摇但不进行代码压缩。
以下是一个示例tsconfig.json
文件的内容:
{
"compilerOptions": {
"removeComments": true,
"sourceMap": true,
"target": "es2015",
"module": "es2015",
"downlevelIteration": true,
"noEmitHelpers": true,
"importHelpers": true
},
"angularCompilerOptions": {
"enableIvy": false
}
}
请注意,这只是一个示例配置文件,你可能需要根据你的项目需求进行调整。