-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix icon in package theme #2
Conversation
It is the recommaned way. Trick code is the double quote inside |
if (loader.test.toString() === '/\\.module\\.css$/') { | ||
loader.exclude = /node_modules/; | ||
loader.test = /\.css$/; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return { | ||
'@primary-color': '#1DA57A', | ||
'@link-color': '#1DA57A', | ||
'@border-radius-base': '2px', | ||
'@icon-url': '/assets/fonts/iconfont/iconfont' | ||
'@icon-url': '"/assets/fonts/iconfont/iconfont"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes u fail is missing the "
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{test: /.woff(?v=\d+.\d+.\d+)?$/, loader: 'url?limit=100000&minetype=application/font-woff'},
{test: /.woff2(?v=\d+.\d+.\d+)?$/, loader: 'url?limit=100000&minetype=application/font-woff'},
{test: /.ttf(?v=\d+.\d+.\d+)?$/, loader: 'url?limit=100000&minetype=application/octet-stream'},
{test: /.eot(?v=\d+.\d+.\d+)?$/, loader: 'file'},
{test: /.svg(?v=\d+.\d+.\d+)?$/, loader: 'url?limit=100000&minetype=image/svg+xml'},
cannot work!!!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用相对路径会报错,绝对路径会导致webpack没有将字体打包~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenxiaojie 后面有解决吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenxiaojie 今天花了两个小时研究,发现同样的问题,真是无语,建议antd团队将字体文件随包发布,而需要CDN引用的再定义modifyVars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phantom0424 没有解决,不优雅的解决了。
将字体和图片放在本项目里面,自己再写一份覆盖。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个双引号问题确实折腾半天,后来恍然大悟
@afc163 你好,我按照您上面的步骤来做,好像还是无法引用到本地的iconfont,不清楚为何,不知道您能帮我看看嘛?我的代码截图如下
package.json 文件:
如上,我是在package.json中直接引用icon-url ,可页面就是无法获取到本地iconfont,希望您帮我看看,打扰了! |
刚过试了一种变通方法,貌似可行。 1.直接复制iconfont目录到node-modules/antd/dist下2.在需要引用的index.less中加入以下代码,注意顺序不能变
不过问题有一个,如果要使用babel-plugin-import配置按需引入antd,设置style:true就会出问题,会加载两份css,解决方案目前是不配置style,也就是antd的css不按需引入 |
@sndraw 官方文档也介绍了,使用theme.js的方式引用iconfont本地资源,是不能配合babel-plugin-import 使用的 |
"theme":{ 是不是去掉@呢 |
@afc163 你好,
请问这个错误该怎么解决,谢谢! |
建议antd团队将字体文件随包发布,而需要CDN引用的再定义modifyVars |
@EugeneHuang95 遇到了 同样的问题,OTS parsing error .有没有解决,求分享方法 |
@afc163 我这里利用引入外部字体成功了,但是有一个小问题,就是获得了本地字体文件以后还是会请求cdn去获取两个字体文件并报错,在这里我已经使用按需加载去设置了,并没有用,而且经过多次测试发现是在dist文件夹里的antd.css里面的@font-face的锅,删除该项即可搞定(因为引入的本地有css文件并覆盖)。但是我不想对node_modules文件夹进行操作,请问有解决的办法吗(目前所有网上能找到的办法都试过) |
@yangzhichao926 你重复引入了样式,即引入了 less 又引入了 css。去掉 css 的引用就好了。 |
@afc163 搞定了大佬,本地icon文件和antd这里全都引用的less,不会报错了 |
简单方法, 我已经实现了webpack打包字体. 说实话这个问题一直在困扰着我. 之前 的解决办法一直是手动复制fonts到node_modules/antd/style/lib/core 目录里面去. 要么就是本地访问. 但是总是有很多问题. 比如: 如果没有放在根目录访问, 那地址就错了. 很麻烦. 现在发现其实直接用相对路径就可以解决. 无奈为啥之前就没有发现呢????
不需要引号里面再包引号之类的. 我的环境是 @import "var.less"; |
以解决, 按需加载antd的情况下,设置 fonts目录 |
@EugeneHuang95 我也遇到同样的问题,create-react-app项目里没有办法直接引用静态文件目录,我只能参考了Restry的方法,在config-overrides.js里通过相对路径来解决,代码如下 |
@a709691139 , 目前看来最好的答案,补充一点
|
@ycscholes 成功配置在create-react-app 下,感谢提点 |
@a709691139 |
@remotesc2 // package.json 防冲突, 改字体文件名为antIconfont
"theme": {
"primary-color": "#1890ff",
"icon-url": "'~fonts/antIconfont'"
} // webpack.js 打包字体到根目录
rules: [{
test: /\.(eot|woff|woff2|ttf|svg)(\?\S*)?$/,
// include: APP_PATH,
loader: 'url-loader?limit=2192&name=fonts/[name].[ext]'
}, |
为什么我配置过这个路径之后,所有Icon引用的图标都编程一个空白方块 |
@SanPy 好像是你的相对路径不对,根路径是node_modules下的antd的路径,一步步../到你的iconfont的路径就可以了 |
@tancyan 好像是这样,谢谢! |
@ycscholes 我把font文件下在src/assets里改名antIconfont
package里添加
不生效呢 还要配置什么吗 请指点一下 |
@nielei19920921
还有检查下webpack配置中是否加了file-loader去处理字体
|
shit ali |
心疼自己,真的是不太容易。。。 |
@EugeneHuang95 字体的静态文件还是需要自己放到执行的目录。 下面是我的解决方案:我把字体下载放到
所以我的 module.exports={
'@icon-url': '/antd/iconFont/iconfont'
} 另外 @afc163,建议你加一下说明,配置本身没有问题,但是容易误导人。最开始看你的配置,我以为字体是打到CSS中,配置的目录是抽离字体放的位置。其实不是,只是字体加载的位置,字体文件资源还是需要自己存放的。 |
Worth adding that in my case, I had to add the I also then had to use |
@EM-Creations use |
if you use ant design pro, the right solution is here: ant-design/ant-design-pro#1088 |
最新最全解决方案:
`
`
完成! ant版本支持0.6.3、1.1.3均测试过 |
经过不断的尝试和参考大家的实现方案,如今终于成功了,不论测试还是生产环境字体文件都是去访问的本地目录。 目录结构: theme.js module.exports = {
"@icon-url": '"~assets/iconfont/iconfont"'
} webpack.config.js const theme = require('../theme')
webpackConfig.module.loaders.push({
test : /\.less/,
loaders : [
'style',
BASE_CSS_LOADER,
'postcss',
`less-loader?{"sourceMap":true,"modifyVars":${JSON.stringify(theme)}}`
]
}) |
macos版本 10.13.6 ,safari 11.1.2 版本. |
其实主要还是less文件里面路径的使用的问题,这里要注意如果你的目录是在alias里面定义过了需要前面加~ |
ant-design/antd-init#133
'@icon-url': '/assets/fonts/iconfont/iconfont',
should be'@icon-url': '"/assets/fonts/iconfont/iconfont"'
. ⚠⚠⚠babel-plugin-import
usestyle: true
.