-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
umi3.1怎么在tsx文件中使用styleName? #4859
Comments
config.ts
|
如何使用的? |
遇到同样的问题,hash生成了,但样式没有被引入。 相关依赖
配置 // .umirc.ts
{
// ...
extraBabelPlugins: [
[
'react-css-modules',
{
exclude: 'node_modules',
generateScopedName: '[name]__[local]___[hash:base64:5]',
filetypes: {
'.less': {
syntax: 'postcss-less',
},
},
},
],
],
} 使用 // src/layout/index.less
.container {
padding: 10px !important;
} // src/layout/index.less
import * as React from 'react';
import { IRouteComponentProps } from 'umi';
import './index.less';
export default function Layout({ children }: IRouteComponentProps) {
return <section styleName="container">{children}</section>;
} 检查 |
Closed
大佬, 你后面解决问题了么, 我的情况一毛一样.... |
可行的方案 umi版本 "umi": "^3.5.20", step1安装包
step2
const GENERATE_PATH = '[path]___[name]__[local]___[hash:base64:5]';
const cssLoaderOptions = {
modules: {
localIdentName: GENERATE_PATH,
auto: (resourcePath: string) => !resourcePath.match(/node_modules/g), // 保证antd样式文件不哈希
},
};
export default defineConfig({
extraBabelPlugins: [
[
'babel-plugin-react-css-modules',
{
exclude: 'node_modules',
generateScopedName: GENERATE_PATH,
filetypes: {
'.less': {
syntax: 'postcss-less',
},
},
},
],
],
cssLoader: cssLoaderOptions
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考了这个回答#1417里的方法,元素的
className
虽然加上了hash
,但是样式实际上没有引入The text was updated successfully, but these errors were encountered: