29
21

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.

Vue CLI v3.0でローカルにあるフォントを適用する

Last updated at Posted at 2018-10-17

Vue CLIでvue createで作成したプロジェクトに、ローカルにあるフォントを適用するのにてこずったので、メモしておく。

  1. src/assets配下にfontsフォルダを作る
  2. src/assets/fontsフォルダにフォントファイルを格納する
  3. src/assets配下にsassフォルダを作る
  4. src/assets/sass配下に以下のようなscssファイルを作る
style.scss
@font-face {
  font-family: 'M PLUS Rounded 1c';
  src: url('~@/assets/fonts/MPLUSRounded1c-Medium.ttf') format('truetype');
}

5.vueのエントリーに当たるmain.jsで以下のように記述し、4.のscssファイルをインポートする

main.js
import './assets/sass/style.scss'

これであとはコンポーネントでfont-familyで上記のフォントを指定してあげれば適用できる。

vue.config.jsをつくってローダーを新たに追加する、なんてことはしなくてよくて、vue cliがいいかんじにフォントのローダーも設定していました。
vue inspect --rulesでwebpackのローダーの設定が確認できます。

29
21
0

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
29
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?