gpt4 book ai didi

fonts - 导出 react-bootstrap 时如何使用 Glyphicons

转载 作者:行者123 更新时间:2023-12-04 23:15:12 27 4
gpt4 key购买 nike

我有 2 个项目:项目1 项目2 .

项目1 用途 react 引导 . 项目1 使用 react-bootstrap 的所有组件并在 react-bootstrap 组件上创建一个包装器(不要问为什么,这是一个要求)。 项目2 应该使用 项目1 (导出时)作为 react-bootstrap 的包装库。

项目1 -->

索引.js:

import { Bootstrap } from 'bootstrap/dist/css/bootstrap.css';
...
import Glyphicon from './src/components/Glyphicon';
...
export default {
...
Glyphicon,
...
};

src/components/Glyphicon.jsx:
import React, { PropTypes } from 'react';
import { RBGlyphicon } from 'react-bootstrap';

const Glyphicon = props => (
<RBGlyphicon
id={props.id}
bsClass={props.clClass}
glyph={props.glyph}
/>
);

Glyphicon.defaultProps = {
id: undefined,
clClass: 'glyphicon',
glyph: undefined,
};

Glyphicon.propTypes = {
id: PropTypes.string,
clClass: PropTypes.string,
glyph: PropTypes.string.isRequired,
};

export default Glyphicon;

webpack.config.js:
const webpack = require('webpack');
const path = require('path');

module.exports = (env = {}) => {
const isProduction = env.production === true;
return {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'Project1.js',
libraryTarget: 'umd',
library: 'Project1',
},
module: {
rules: [
{
test: /.(js|jsx)?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff',
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/octet-stream',
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml',
},
],
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
new webpack.optimize.UglifyJsPlugin(),
],
};
};

I export this Project1 as a bundle called Project1 using webpack and copy it in Project2 in src folder. I don't copy the font files generated in this build



现在问题开始于 Glyphicons .

项目2 -->

源代码/应用程序.jsx:
import React, { Component } from 'react';
import Project1 from './Project1';
...
export default class App extends Component {
render() {
return (
<div>
...
<Project1.Glyphicon glyph="camera" />Camera
...
</div>
);
}
}
export default App;

索引.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './src/App';

ReactDOM.render(<App />, document.getElementById('root'));

索引.html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
</head>
<body>
<div id="root">
</div>
<script src='/bundle.js'></script>
</body>
</html>

我使用 webpack-dev-server 来构建 项目2 并在浏览器中运行。当我在 中使用 Glyphicon.jsx 时项目2 ,图标不会显示在浏览器中。以下是 Chrome 浏览器控制台中显示的错误:

Chrome Browser Debug Console errors

现在我知道问题与字体有关。

Even if I copy these generated font files and paste in root of Project2, I still get same errors.



我应该怎么做才能从 导出这些字体文件项目1 以便它们可以用于 项目2 ?

最佳答案

Bootstrap 4 不支持字形图标,无论是用户 bootstrap 3 还是使用很棒的字体。

bootstrap doc

关于fonts - 导出 react-bootstrap 时如何使用 Glyphicons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43863271/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com