我在一个新的 React 项目中使用 CSS 模块(通过 Webpack css 加载器),尽管它工作得很好,但我在获取 SCSS 时遇到了困难反应选择 https://github.com/JedWatson/react-select上班。我想这是因为它试图创造local
classNames,其中的JSreact-select
是不知道的。有没有办法导入整个.scss
文件,但范围是全局而不是本地?
我通常定义两个 CSS 加载器,如下所示:
// Global CSS
// We make the assumption that all CSS in node_modules is either
// regular 'global' css or pre-compiled.
loaders.push({
test: /\.css$/,
include: /node_modules/,
loader: 'style-loader!css-loader'
});
// CSS modules
loaders.push({
test: /\.css$/,
exclude: /node_modules/,
loader: 'style-loader!css-loader?modules'
});
我过去也将应用程序迁移到 CSS 模块,发现基于文件扩展名定义约定很有用,例如{filename}.module.css === CSS 模块 vs {filename}.css === 全局 CSS
// Global CSS
loaders.push({
test: /\.css$/,
exclude: /\.module\.css$/,
loader: 'style-loader!css-loader'
});
// CSS modules
loaders.push({
test: /\.module\.css$/,
loader: 'style-loader!css-loader?modules'
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)