Skip to content

Commit

Permalink
chore: support svg loader (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng authored Jun 29, 2022
1 parent ff2f7f0 commit 1d4eeb1
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 5 deletions.
8 changes: 5 additions & 3 deletions view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lodash.get": "^4.4.2",
"lodash.uniqby": "^4.7.0",
"macaca-cli": "2",
"macaca-electron": "7",
"macaca-electron": "18",
"macaca-wd": "3",
"mini-css-extract-plugin": "^0.4.0",
"postcss-loader": "^2.1.6",
Expand All @@ -69,6 +69,9 @@
"react-router-dom": "^4.2.2",
"style-loader": "^0.21.0",
"stylelint": "^9.3.0",
"svg-sprite-loader": "^6.0.11",
"svgo": "^2.8.0",
"svgo-loader": "^3.0.0",
"url-loader": "^1.1.2",
"url-parse": "^1.4.3",
"webpack": "^4.10.0",
Expand All @@ -80,6 +83,5 @@
},
"dependencies": {
"dayjs": "^1.7.7"
},
"licenses": "MIT"
}
}
41 changes: 41 additions & 0 deletions view/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions view/src/components/Icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import classnames from 'classnames';

function Icon(props) {
const { className, type, width, height, fill, radius, style = {} } = props;
return (
<svg
className={classnames('icon-svg', className)}
style={Object.assign({
width,
height: height || width,
minWidth: width,
fill,
borderRadius: radius,
}, style)}
>
<use xlinkHref={`#${type}`} />
</svg>
);
}

export default Icon;
6 changes: 5 additions & 1 deletion view/src/components/SiderBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SettingOutlined,
} from '@ant-design/icons';
import { FormattedMessage } from 'react-intl';
import Icon from './Icon';

const Sider = Layout.Sider;

Expand All @@ -32,7 +33,10 @@ export default class SiderBar extends React.Component {
>
<div className="logo">
<Link to="/">
<img alt="logo" src="https://macacajs.github.io/reliable/logo/reliable.svg" />
<Icon
width={30}
type="logo"
/>
<h1>Reliable</h1>
</Link>
</div>
Expand Down
6 changes: 6 additions & 0 deletions view/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const chooseLocale = () => {
};
}
};

const importAll = (r) => {
return r.keys().forEach(r);
};
importAll(require.context('./assets', false, /\.svg$/));

const lang = chooseLocale();

window.addEventListener('load', () => {
Expand Down
13 changes: 12 additions & 1 deletion view/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ module.exports = (env, argv) => {
],
}, {
test: /\.svg$/,
loader: 'url-loader',
use: [
{
loader: 'svg-sprite-loader',
options: {
symbolId: '[name]',
},
},
{
loader: 'svgo-loader',
},
],
include: [path.resolve(__dirname, 'src', 'assets')],
},
],
},
Expand Down

0 comments on commit 1d4eeb1

Please sign in to comment.