当我在js文件(例如import style from './node_modules/package/css/input.css'
)中导入CSS时,就可以了。但是,当我尝试将其导入到CSS中时,它不会将类注入组件中
input.styl
@import '~package/css/input.css'
.color
color: red
input.tsx
import style from './input.styl'
function Input() {
return (
<div className={ style.container }>
<input className={ style.color } />
</div>
)
}
它输出css文件:.container-wGX2p {...} .color-3NOmr {...}
但是在呈现的html中的div
元素上没有导入的类:<div><input class="color-3NOmr"></div>
Webpack配置:
{ test: /\.tsx?$/i,
use: [
'babel-loader',
{ loader: 'ts-loader',
options: {
transpileOnly: true,
}
}
],
},
{ test: /\.styl$/i,
use: [
{ loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '/assets/',
}
},
{ loader: 'css-loader',
options: {
localsConvention: 'camelCase',
modules: {
localIdentName: '[local]-[hash:base64:5]',
}
}
},
'postcss-loader',
'stylus-loader'
]
},