导入CSS不适合使用WebPack 5和CSS Loader的dashes的班级名称工作5
试图获取一个导入CSS来使用我的应用程序的第三方库。
我正在使用WebPack V5和CSS-Loader V5。由于从WebPack V4升级到V5,因此第三方库样式不再工作,因为CSS-Loader不允许命名出口,因此
import('./styles.css').then((styles) => console.log(styles))
会产生类似于styles.default.xxx而不是styles.xxx的
功能。在CSS-LOADER中是正确的选项。这将使我能够访问styles.xxx,而无需默认。但是,如果我将名为Export设置为css-loader中为true,我将无法再用破折号导入类(例如“以BTN为注重的”,因为CSS-Loader会将其转换为“ BTNFOCUSED”,并且第三方库将其称为样式的样式。 ['以BTN为中心的'])。我在CSS-LOADER中看到了一个选项ExportLocalsConvention,但是此选项仅限于“ camelcaseonly”或“ dashesonly”,而newsexport设置为true,并且这两个选项都无济于事。
Trying to get a third party library that is importing css to work with my app.
I am using webpack v5 and css-loader v5. Since the upgrade from webpack v4 to v5, the 3rd party library styles are no longer working because css-loader doesn't allow named exports, hence
import('./styles.css').then((styles) => console.log(styles))
will yield something like styles.default.xxx instead of styles.xxx
A workaround would be setting namedExport option to be true in css-loader. This will enable me to access styles.xxx without the default. However if I set namedExport to be true in css-loader, I can no longer import classes with dashes (e.g. "btn-focused" because css-loader will convert it to "btnFocused" and the third party library refers to the styles as styles['btn-focused']). I see an option exportLocalsConvention in css-loader, however this option is restricted to 'camelCaseOnly' or 'dashesOnly' when namedExport is set to true, and both of these options do not help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过
样式加载程序
?尝试以下配置!它在动态导入中起作用:随时让我知道是否有任何问题:)
Did you try
style-loader
? Give the following configuration a try! It works in dynamic imports:Feel free to let me know if there is any problem with it :)