Reputation: 11
I am pretty new with Expo and react-native. I am facing a problem to load styles as module with css-loader. I tried a lot of things to customize the webpack.config.js with Expo documentation but it doesn't work !
If someone can help, I would be so grateful because I spent so many times on this problem...
Reproduce issue:
expo init my-app
My webpack.config.js
const createExpoWebpackConfigAsync = require('@expo/webpack-config');
module.exports = async function (env, argv) {
const config = await createExpoWebpackConfigAsync(
{
...env,
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
loader: "style-loader"
},
{
test: /\.css$/,
loader: "css-loader",
options: {
modules: true,
}
}
],
},
extensions: [ '.web.js', '.js', '.jsx', '.css' ],
},
argv
);
return config;
};
My component: menu.jsx
import React from 'react';
import styles from './menu.module.css';
console.log(styles); // Displaying {}
class Menu extends React.Component {
render() {
return <div className={styles.red}>a</div>
}
}
export default Menu;
My style: menu.module.css
.red {
width: 300px;
height: 300px;
display: block;
background-color: red;
}
Upvotes: 1
Views: 4219
Reputation: 1495
if you want to write style like normal css, have a look on styled-componenet
Upvotes: 2