我有两个问题。
1) CSS Loader和Style Loader是两台webpack装载机。我不能理解这两者之间的区别。为什么我必须使用两个加载器,而它们都做相同的工作?
2)上述Readme.md文件中提到的.useable.less和.useable.css是什么?
发布于 2016-10-13 02:22:13
为了回答第二个问题“上述Readme.md文件中提到的.useable.less和.useable.css是什么?”,默认情况下,当样式为require'd
时,样式加载器模块会自动将<script>
标记注入到DOM中,并且该标记将一直保留在DOM中,直到关闭或重新加载浏览器窗口为止。样式加载器模块还提供了所谓的“引用计数API”,允许开发人员添加样式,并在以后不再需要它们时将其删除。API的工作原理如下:
const style = require('style/loader!css!./style.css')
// The "reference counter" for this style starts at 0
// The style has not yet been injected into the DOM
style.use() // increments counter to 1, injects a <style> tag
style.use() // increments counter to 2
style.unuse() // decrements counter to 1
style.unuse() // decrements counter to 0, removes the <style> tag
按照惯例,使用此API加载的样式表具有扩展名".usable.css“,而不是像上面那样简单地使用".css”。
发布于 2019-11-05 03:11:19
Webpack文档建议结合使用style-loader和css-loader:
https://stackoverflow.com/questions/34039826
复制相似问题