Skip to content
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

引入自定义字体时webpack打包报错 #34

Open
shiiiiiiji opened this issue Jul 11, 2018 · 3 comments
Open

引入自定义字体时webpack打包报错 #34

shiiiiiiji opened this issue Jul 11, 2018 · 3 comments

Comments

@shiiiiiiji
Copy link
Owner

shiiiiiiji commented Jul 11, 2018

今天基于iconfont封装Icon组件的时候,当引入字体样式后,webpack一直报错,如下:

@font-face {font-family: "ytui-icon";
  src: url('./iconfont.eot?t=1531298415150'); /* IE9*/
  src: url('./iconfont.eot?t=1531298415150#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAqUAAsAAAAAD4AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAAQwAAAFZW7kguY21hcAAAAYAAAACRAAAB9vtUBxpnbHlmAAACFAAABigAAAhwKcmwImhlYWQAAAg8AAAALwAAADYToArbaGhlYQAACGwAAAAeAAAAJAmHBUJobXR4AAAIjAAAABkAAAAsLZ8AAGxvY2EAAAioAAAAGAAAABgKzAy8bWF4cAAACMAAAAAfAAAAIAEaAGBuYW1lAAAI4AAAAU8AAAJ5oPQT1nBvc3QAAAowAAAAYQAAAIRhYKFqeJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2BkUWOcwMDKwMHUyXSGgYGhH0IzvmYwYuRgYGBiYGVmwAoC0lxTGBwYKp6JMTf8b2CIYW5gaAAKM4LkAOEtC7EAeJzFkcsRwjAMRJ8TYyDDBMInVVACBXHi7BKoVG2EtZQLFUQzzxrJlu3ZBXZAL54iQ/qQaPFWN3m/Z/B+5qW6KCc6qs3Lorra6FlHtFc8d5rJurmw58DR5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OIgnfsq8fw2Xxm4WRhA4Hr243wE/b+BdSVzA5DLwcAEEgUAK58LFAB4nGNgZGBgbvjfwBDDuo0BCFhXMjAyoAJuAGWQA9UAAHicY2FgYGB+ycDAwgDBrNsQbHQMADrxAcwAAAAAAAAAAHYA+gF6AY4CDAKIAvADdAPgBDh4nGNgZGBg4GYIYWBlAAEmIOYCQgaG/2A+AwASGgF7AHicbZE7TsNAFEWv80NxBEUQlDANFKA4nwYpJZGSgo4ifeKMnUS2xxqPI3kJrIc1sAJ6OtZAy40zuAjxaJ7Ove/jJw2ALr7g4PBd8R7YQZvqwDWc4cZynf6d5QbZs9xEB0+WW/SfLbt4xIvlDi6x4wSn0aZ6wJtlhzu8W67hAh+W6/Q/LTfI35abuMaP5Ra6zrllF3Pn1nIH907uTrRcGLkSy0JsfJUEKjFuYfJNb69eZZhHC13pCuZSZxuViKE3qLyZTKT+m5XtwpExgQi0isWUQ2UUKZFqtZW+8dbGpON+P7C+56uYq02gIbGAYVxBYImCcQMfCgmCMhrWFYw5/V6Ve2VHSC9itz6R/+/M2aGRUe+VwJDPNDhRN2NdUtYe75XxoUKM6BruJng1O2LS1G4quU9EFkjL3JaOT9/DuuxKMUafJziq98p/x7/PQHE2AHicbcZRCoAgEEXReZVZ1lZcVNiEUTiWCi2/IPrrwIVLFb0M/RtQoUYDhRYaHXoYDBgJ1xhPTs7uIluJKnoJrJxnt2nP05w4d0fhlFcJ5hu71HmN6sku2klIZc9ENxsEGrkAAAA=') format('woff'),
  url('./iconfont.ttf?t=1531298415150') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('./iconfont.svg?t=1531298415150#ytui-icon') format('svg'); /* iOS 4.1- */
}
ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/Icon/index.scss
    Module not found: Error: Can't resolve './iconfont.eot?t=1531298415150' in 'D:\Dev\yt\Nodejs\npm\YTUI\src\Icon'
     @ ./~/css-loader!./~/postcss-loader!./~/sass-loader!./src/Icon/index.scss 6:86-127 6:162-203
     @ ./src/Icon/index.scss
     @ ./src/Icon/index.js
     @ ./src/index.js

后来查阅资料时发现webpack不能识别css内的相对路径(js可以),将引用路径改成这样就可以:

@font-face {font-family: "ytui-icon";
  src: url('~/iconfont.eot?t=1531298415150'); /* IE9*/
  src: url('~/iconfont.eot?t=1531298415150#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAqUAAsAAAAAD4AAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAAQwAAAFZW7kguY21hcAAAAYAAAACRAAAB9vtUBxpnbHlmAAACFAAABigAAAhwKcmwImhlYWQAAAg8AAAALwAAADYToArbaGhlYQAACGwAAAAeAAAAJAmHBUJobXR4AAAIjAAAABkAAAAsLZ8AAGxvY2EAAAioAAAAGAAAABgKzAy8bWF4cAAACMAAAAAfAAAAIAEaAGBuYW1lAAAI4AAAAU8AAAJ5oPQT1nBvc3QAAAowAAAAYQAAAIRhYKFqeJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2BkUWOcwMDKwMHUyXSGgYGhH0IzvmYwYuRgYGBiYGVmwAoC0lxTGBwYKp6JMTf8b2CIYW5gaAAKM4LkAOEtC7EAeJzFkcsRwjAMRJ8TYyDDBMInVVACBXHi7BKoVG2EtZQLFUQzzxrJlu3ZBXZAL54iQ/qQaPFWN3m/Z/B+5qW6KCc6qs3Lorra6FlHtFc8d5rJurmw58DR5wubRdru6f84+fpdK6lCXdEXbQykHnYOmjN2CZo7NgXNNbsGTXO7BdIbuwdSHnsE8gCbA4YfemYcZwAAAHichZVdjBvVFcfvuXfmejxjj2c8M3fs9dieD3uGjZdd44+ZDZt1ApsSFdICjdVsUKISooh+kAKtSBBJ6PaLNhJFoJAH+kKKkBB0eaF55CEvKbT7wlOlqEJJP4RKhehT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+AwASGgF7AHicbZE7TsNAFEWv80NxBEUQlDANFKA4nwYpJZGSgo4ifeKMnUS2xxqPI3kJrIc1sAJ6OtZAy40zuAjxaJ7Ove/jJw2ALr7g4PBd8R7YQZvqwDWc4cZynf6d5QbZs9xEB0+WW/SfLbt4xIvlDi6x4wSn0aZ6wJtlhzu8W67hAh+W6/Q/LTfI35abuMaP5Ra6zrllF3Pn1nIH907uTrRcGLkSy0JsfJUEKjFuYfJNb69eZZhHC13pCuZSZxuViKE3qLyZTKT+m5XtwpExgQi0isWUQ2UUKZFqtZW+8dbGpON+P7C+56uYq02gIbGAYVxBYImCcQMfCgmCMhrWFYw5/V6Ve2VHSC9itz6R/+/M2aGRUe+VwJDPNDhRN2NdUtYe75XxoUKM6BruJng1O2LS1G4quU9EFkjL3JaOT9/DuuxKMUafJziq98p/x7/PQHE2AHicbcZRCoAgEEXReZVZ1lZcVNiEUTiWCi2/IPrrwIVLFb0M/RtQoUYDhRYaHXoYDBgJ1xhPTs7uIluJKnoJrJxnt2nP05w4d0fhlFcJ5hu71HmN6sku2klIZc9ENxsEGrkAAAA=') format('woff'),
  url('~/iconfont.ttf?t=1531298415150') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
  url('~/iconfont.svg?t=1531298415150#ytui-icon') format('svg'); /* iOS 4.1- */
}

就打包成功了,webpack: Compiled successfully.


参考资料:

@shiiiiiiji shiiiiiiji added the BUG label Jul 11, 2018
@Yatoo2018
Copy link

webpack: 这锅我不背,请把锅丢给loader

@YunFeng0817
Copy link

同样的问题,看了楼主的之后解决了

@shiiiiiiji
Copy link
Owner Author

@Mark-Fritz 🤪

@shiiiiiiji shiiiiiiji removed the BUG label Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants