gpt4 book ai didi

reactjs - 如何配置 webpack 以在 React 中加载 glyphicons/font-awesome 图标

转载 作者:行者123 更新时间:2023-12-04 03:21:06 28 4
gpt4 key购买 nike

在 React 项目中使用 bootstrap 时,运行开发环境工作正常。但是当我为包项目运行 npm build 时。显示引导字体错误。

ERROR in ./~/bootstrap/dist/fonts/glyphicons-halflings-regular.eot
Module parse failed: /Users/xx/WorkDir/react-leap/node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.eot Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '�' (1:0)
at Parser.pp.raise (/Users/xx/WorkDir/react-leap/node_modules/webpack/node_modules/acorn/dist/acorn.js:923:13)
at Parser.pp.getTokenFromCode (/Users/xx/WorkDir/react-leap/node_modules/webpack/node_modules/acorn/dist/acorn.js:2831:8)

我的 Webpack 配置

module: {
loaders: [
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
loader: 'file-loader',
include: paths
}
]
}

引导版本:

"bootstrap": "3.3.6",

最佳答案

我遇到了一个解决方案:

webpack.config.js

 module: {
preLoaders: [
{test: /\.js$/, exclude: /node_modules/, loader: 'jshint-loader'}
],
loaders: [
{test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery' },
{test: /\.less$/, loader: 'style-loader!css-loader!less-loader'},
{test: /\.css$/, loader: 'style-loader!css-loader'},
{test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/font-woff" },
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
{test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }
]
}

确保安装所有这些加载器

npm i jshint-loader style-loader css-loader less-loader url file --save-dev

在此导入 Bootstrap 之后,您的文件为

require('bootstrap/less/bootstrap.less');

关于reactjs - 如何配置 webpack 以在 React 中加载 glyphicons/font-awesome 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38449390/

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