使用 Angular 11 将 CSS 提取到 JS(不推荐使用的 extractCss) [英] Extracting CSS into JS with Angular 11 (deprecated extractCss)

查看:44
本文介绍了使用 Angular 11 将 CSS 提取到 JS(不推荐使用的 extractCss)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 Angular 11 应用程序来创建 Web 组件.为此,有必要将所有样式内联捆绑到一个 JS 文件中.在 Angular 11 之前,我们曾经在 angular.json 配置中使用 extractCss: false 来做到这一点.现在这个选项已被标记为已弃用,我还没有找到任何关于现在应该如何完成的文档.注意.extractCss: false 目前仍然有效.

We are using an Angular 11 app to create a web component. For this it is necessary that all styles are bundled inline into a single JS file. Before Angular 11, we used to do this with extractCss: false in then angular.json config. Now this option has been marked deprecated, and I have not found any documentation on how this should be accomplished now. NB. The extractCss: false still works for the moment.

推荐答案

Angular CLI 11.0 的一项更改是 extractCss 配置属性的弃用.

One of the changes for Angular CLI 11.0 is deprecation of extractCss configuration property.

出现错误extractCss is deprecated"是因为它现在的默认值为true.extractCss 可以安全地从 angular.json 中删除,或者在升级原理图期间应该为你做.这意味着我们在应用程序构建期间不再使用 styles.js.升级后,迁移示意图应删除未使用的属性或将其替换为新的替代项.

Getting error "extractCss is deprecated" comes because it has default value as true now. extractCss can be safely removed from angular.json or during the upgrade schematics should do it for you. This means that we don’t use styles.js anymore during the application build. The migration schematic should remove unused properties or replace them with the new alternative once you do the upgrade.

https://angular.io/cli/build

--extract-css

--extract-css

已弃用:自 11.0 版起已弃用.不再需要禁用 HMR 的 CSS 提取.从全局样式中提取 CSS 到'.css' 文件而不是 '.js'.

Deprecated: Deprecated since version 11.0. No longer required to disable CSS extraction for HMR. Extract CSS from global styles into '.css' files instead of '.js'.

这篇关于使用 Angular 11 将 CSS 提取到 JS(不推荐使用的 extractCss)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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