【发布时间】:2021-10-18 20:41:36
【问题描述】:
我想使用 codegen.macros 根据 Web 或本机输出加载不同的库。但是我的 web 组件需要加载 css / scss 文件。我真的在谷歌上搜索了一下,但我找不到一个运行示例如何调整 webpack.config.js 以使 css/scss 加载器与 Expo Web (react-native-web) 一起运行。
博览会是强制性的。
它总是以“无法解析 ....css”结束。
我知道 react native 需要 JS 中的 CSS,但我的方法将加载基于 web 或本地 (ios / android) 的不同组件。
我的设置已经运行良好,但我无法加载和注入第三方 css 文件。这是我的 webpack.config.js 文件。
const createExpoWebpackConfigAsync = require('@expo/webpack-config')
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync({
...env,
// Passing true will enable the default Workbox + Expo SW configuration.
},
argv
);
// Customize the config before returning it.
config.module.rules.push({
test: /\.((c|sa|sc)ss)$/i,
use: [{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
],
}, );
return config
}
【问题讨论】:
-
看起来 CSS 加载器运行良好,我在导入时出错了。但我无法导入 SCSS 文件。他们确实导入没有错误,但不会注入 scss 样式
标签: css react-native webpack expo react-native-web