Angular 2(Cli)不缩小astet/css文件 [英] Angular 2 (Cli) not minifying asstet/css files

查看:79
本文介绍了Angular 2(Cli)不缩小astet/css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Angular-cli 用Angular 2创建了一个项目. 当我运行

    ng build --prod

我没有缩小js和CSS文件.这些文件位于资产/js/资产/css/中.

我如何缩小它们?谢谢!

解决方案

资产文件夹包含在您的构建中,因为该文件夹在angular-cli.json的资产数组中列出.

资产数组中的所有内容均按原样"复制在构建版本中.

如果将您的CSS和脚本添加到angular-cli.json中的样式和脚本-arrays中,它们将在构建时捆绑在一起,以便您的所有CSS都在styles.bundle.js中(是js).

您不应在index.html中引用css或js文件,angular-cli会将捆绑包插入index.html.

如果您仍然希望文件保存在Assets文件夹中,请记住它是按原样"复制的,因此您可以使用任何喜欢的工具来缩小该文件夹中的内容(例如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)不缩小astet/css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆