Skip to content

Commit fa215c5

Browse files
author
chenghao
committed
增加自定义样式
1 parent 43f7ea5 commit fa215c5

File tree

5 files changed

+110
-13
lines changed

5 files changed

+110
-13
lines changed

config/webpack.config.dev.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module.exports = {
111111
// Webpack 2 fixes this, but for now we include this hack.
112112
// https://github.com/facebookincubator/create-react-app/issues/1713
113113
/\.(js|jsx)(\?.*)?$/,
114+
/\.less$/,
114115
/\.css$/,
115116
/\.json$/,
116117
/\.svg$/
@@ -127,13 +128,20 @@ module.exports = {
127128
include: paths.appSrc,
128129
loader: 'babel',
129130
query: {
130-
131+
plugins: [
132+
['import', [{ libraryName: "antd", style: true }]],
133+
],
131134
// This is a feature of `babel-loader` for webpack (not Babel itself).
132135
// It enables caching results in ./node_modules/.cache/babel-loader/
133136
// directory for faster rebuilds.
134137
cacheDirectory: true
135138
}
136139
},
140+
// 解析 less 文件,并加入变量覆盖配置
141+
{
142+
test: /\.less$/,
143+
loader: 'style!css!postcss!less?{modifyVars:{"@primary-color":"#404040"}}'
144+
},
137145
// "postcss" loader applies autoprefixer to our CSS.
138146
// "css" loader resolves paths in CSS and adds assets as dependencies.
139147
// "style" loader turns CSS into JS modules that inject <style> tags.

config/webpack.config.prod.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
exclude: [
110110
/\.html$/,
111111
/\.(js|jsx)$/,
112+
/\.less$/,
112113
/\.css$/,
113114
/\.json$/,
114115
/\.svg$/
@@ -124,7 +125,11 @@ module.exports = {
124125
test: /\.(js|jsx)$/,
125126
include: paths.appSrc,
126127
loader: 'babel',
127-
128+
query: {
129+
plugins: [
130+
['import', [{ libraryName: "antd", style: true }]],
131+
]
132+
}
128133
},
129134
// The notation here is somewhat confusing.
130135
// "postcss" loader applies autoprefixer to our CSS.
@@ -147,6 +152,14 @@ module.exports = {
147152
)
148153
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
149154
},
155+
{
156+
test: /\.less$/,
157+
loader: ExtractTextPlugin.extract(
158+
'css?sourceMap&!' +
159+
'postcss!' +
160+
'less-loader?{"sourceMap":true,"modifyVars":{"@primary-color":"#404040"}}'
161+
),
162+
},
150163
// JSON is not enabled by default in Webpack but both Node and Browserify
151164
// allow it implicitly so we also enable it.
152165
{

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "react-admin",
33
"version": "0.1.0",
44
"private": true,
5+
"homepage": ".",
56
"devDependencies": {
67
"autoprefixer": "6.7.2",
78
"babel-core": "6.22.1",

src/App.js

+62-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,70 @@
11
import React, { Component } from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
2+
import { Layout, Menu, Breadcrumb, Icon } from 'antd';
3+
const { Header, Content, Footer, Sider } = Layout;
4+
const SubMenu = Menu.SubMenu;
5+
import './index.less';
46

57
class App extends Component {
8+
state = {
9+
collapsed: false,
10+
mode: 'inline',
11+
};
12+
onCollapse = (collapsed) => {
13+
console.log(collapsed);
14+
this.setState({
15+
collapsed,
16+
mode: collapsed ? 'vertical' : 'inline',
17+
});
18+
};
619
render() {
720
return (
8-
<div className="App">
9-
<div className="App-header">
10-
<img src={logo} className="App-logo" alt="logo" />
11-
<h2>Welcome to React</h2>
12-
</div>
13-
<p className="App-intro">
14-
To get started, edit <code>src/App.js</code> and save to reload.
15-
</p>
16-
</div>
21+
<Layout>
22+
<Sider
23+
collapsible
24+
collapsed={this.state.collapsed}
25+
onCollapse={this.onCollapse}
26+
>
27+
<div className="logo" />
28+
<Menu theme="dark" mode={this.state.mode} defaultSelectedKeys={['6']}>
29+
<SubMenu
30+
key="sub1"
31+
title={<span><Icon type="user" /><span className="nav-text">User</span></span>}
32+
>
33+
<Menu.Item key="1">Tom</Menu.Item>
34+
<Menu.Item key="2">Bill</Menu.Item>
35+
<Menu.Item key="3">Alex</Menu.Item>
36+
</SubMenu>
37+
<SubMenu
38+
key="sub2"
39+
title={<span><Icon type="team" /><span className="nav-text">Team</span></span>}
40+
>
41+
<Menu.Item key="4">Team 1</Menu.Item>
42+
<Menu.Item key="5">Team 2</Menu.Item>
43+
</SubMenu>
44+
<Menu.Item key="6">
45+
<span>
46+
<Icon type="file" />
47+
<span className="nav-text">File</span>
48+
</span>
49+
</Menu.Item>
50+
</Menu>
51+
</Sider>
52+
<Layout>
53+
<Header style={{ background: '#fff', padding: 0 }} />
54+
<Content style={{ margin: '0 16px' }}>
55+
<Breadcrumb style={{ margin: '12px 0' }}>
56+
<Breadcrumb.Item>User</Breadcrumb.Item>
57+
<Breadcrumb.Item>Bill</Breadcrumb.Item>
58+
</Breadcrumb>
59+
<div style={{ padding: 24, background: '#fff', minHeight: 360 }}>
60+
Bill is a cat.
61+
</div>
62+
</Content>
63+
<Footer style={{ textAlign: 'center' }}>
64+
Ant Design ©2016 Created by Ant UED
65+
</Footer>
66+
</Layout>
67+
</Layout>
1768
);
1869
}
1970
}

src/index.less

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#root{
2+
height: 100%;
3+
}
4+
.ant-layout{
5+
height: 100%;
6+
.logo{
7+
height: 32px;
8+
background: #333;
9+
border-radius: 6px;
10+
margin: 16px;
11+
}
12+
.ant-layout-sider-collapsed{
13+
.anticon{
14+
font-size: 16px;
15+
margin-left: 8px;
16+
}
17+
.nav-text{
18+
display: none;
19+
}
20+
.ant-menu-submenu-vertical > .ant-menu-submenu-title:after{
21+
display: none;
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)