问题描述
我使用 Angular-cli 创建了一个 Angular 2 项目.当我跑
ng build --prod
我没有缩小我的 js 和 css 文件.这些文件位于 assets/js/ 和 assets/css/.
我如何缩小它们?谢谢!
assets-folder 包含在您的构建中,因为该文件夹列在 angular-cli.json 的 assets-array 中.
assets-array 中的所有内容都在构建时按原样"复制.
如果您将 css 和脚本添加到 angular-cli.json 中的样式和脚本数组中,它们将在构建时捆绑在一起,以便您的所有 css 都在 style.bundle.js 中(是的 js).
不应在 index.html 中引用 css 或 js 文件,angular-cli 会在 index.html 中插入包.
如果您仍然希望文件位于 assets 文件夹中,请记住它是按原样"复制的,以便您可以使用任何您喜欢的工具来缩小该文件夹中的内容,(例如 https://www.npmjs.com/package/minifier) angular-cli 不会碰它,只是在构建时复制它.>
I created a project with Angular 2 using Angular-cli.When I run
ng build --prod
I don't have my js and css files minifyed. These files are located in assets/js/ and assets/css/.
How do I minify them? Thanks!
the assets-folder is included in your build because the folder is listed in the assets-array in angular-cli.json.
everything in the assets-array is copied "as-is" on build.
if you add your css and scripts to the styles and scripts -arrays in angular-cli.json they will be bundled on build so that all your css will be in styles.bundle.js (yes js).
you should not reference the css or js files in your index.html, angular-cli will insert the bundles in index.html.
If you still want the files to live inside the assets folder, remember it is copied "as is" so you can use any tool you like to minify whats in that folder, (e.g. https://www.npmjs.com/package/minifier) angular-cli will not touch it, just copy it on build.
这篇关于Angular 2 (Cli) 不缩小 asstet/css 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!