Run-time solution ( without eject )
install react-rewired and customize-cra to have an option to update config on run-time
npm i react-app-rewired
npm i customize-cra
create file config-overrides.js in the package.json folder with content :
const {
override,
addWebpackModuleRule
} = require("customize-cra");
module.exports = override(
addWebpackModuleRule({
test: /\.styl$/,
exclude: /(node_modules)/,
loaders: [
'style-loader',
{
loader: 'css-loader',
options: {url: false}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: (loader) => [require('autoprefixer')()]
}
},
'stylus-loader'
]
}),
addWebpackModuleRule({
test: /\.css$/,
use: [
'style-loader',
'css-loader',
]
})
);
install stylus
npm i stylus
npm i stylus-loader
npm i css-loader
change your start / build scripts to use react-rewired
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
...
Then you can import your styles from .styl files in your React components
require('./style/index.styl');
OR
import style from './СomponentStyle.styl'; --> className={style.container}
This all :) Additional thanks to Denis Bubnov in current topic - you helped me much to implement current solution!
Babel Plugin
section) – Saki