6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails-assets-fontawesome 4.4.0 にアップデートしたらフォントが迷子に

Last updated at Posted at 2015-08-05

@font-faceのところでパスが../fonts/xxxxxになってたのが原因だったので

app/assets/stylesheets/application.css.scss
 *= require fontawesome

するのやめて、強引に

app/assets/stylesheets/application.css.scss
$fa-font-path: "fontawesome/fonts";
@import "fontawesome";

したら見つかった。

application.css.scssが汚れていくのは気持ち悪いなー。
bootstrap-sass-officialも同じ感じやし、requireはそのままにして、別ファイルに上書く変数ぶっ込んでしまったほうがいいのかしら?

追記

ちょっとproductionで使うことがあってデプロイしてみたらまた迷子になってた。
というよりもAssetPipelineの影響だった。

asset compile 編を見てなるほどなーと思いつつ現実的な解決策を探してみた。

本家様

app/assets/stylesheets/fontawesome.scss
@import 'fontawesome/font-awesome.scss';

ふむ。

app/assets/stylesheets/fontawesome/font-awesome.scss
/*!
 *  Font Awesome 4.4.0 by @davegandy - http://fontawesome.io - @fontawesome
 *  License - http://fontawesome.io/license (Font: SIL OFL 1.1, CSS: MIT License)
 */

@import "variables";
@import "mixins";
@import "path";
@import "core";
@import "larger";
@import "fixed-width";
@import "list";
@import "bordered-pulled";
@import "animated";
@import "rotated-flipped";
@import "stacked";
@import "icons";

あ、うん。相対パスか。

@import "fontawesome";している以上、外部からどうにもならなさそう。
ということで、この際fontawesome(正確にはfontawesome/font-awesome.scss)で@importしているものを個別にいれて、fontawesome/_path.scssだけ上書きしちゃえ!ということで以下の設定に落ち着いた。

app/assets/stylesheets/application.css.scss
$fa-font-path: "fontawesome/fonts";
//@import "fontawesome";
@import "fontawesome/variables";
@import "fontawesome/mixins";
@import "fontawesome/path";
@import "fontawesome/core";
@import "fontawesome/larger";
@import "fontawesome/fixed-width";
@import "fontawesome/list";
@import "fontawesome/bordered-pulled";
@import "fontawesome/animated";
@import "fontawesome/rotated-flipped";
@import "fontawesome/stacked";
@import "fontawesome/icons";
app/assets/stylesheets/fontawesome/_path.scss
/* FONT PATH
 * -------------------------- */

@font-face {
  font-family: 'FontAwesome';
  src: font-url('#{$fa-font-path}/fontawesome-webfont.eot?v=#{$fa-version}');
  src: font-url('#{$fa-font-path}/fontawesome-webfont.eot?#iefix&v=#{$fa-version}') format('embedded-opentype'),
    font-url('#{$fa-font-path}/fontawesome-webfont.woff2?v=#{$fa-version}') format('woff2'),
    font-url('#{$fa-font-path}/fontawesome-webfont.woff?v=#{$fa-version}') format('woff'),
    font-url('#{$fa-font-path}/fontawesome-webfont.ttf?v=#{$fa-version}') format('truetype'),
    font-url('#{$fa-font-path}/fontawesome-webfont.svg?v=#{$fa-version}#fontawesomeregular') format('svg');
//  src: font-url('#{$fa-font-path}/FontAwesome.otf') format('opentype'); // used when developing fonts
  font-weight: normal;
  font-style: normal;
}
6
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?