Help us understand the problem. What is going on with this article?

[Rails 5.1]webpackerを使用して、Spectre.cssを適用する方法

More than 1 year has passed since last update.

はじめに

Rails 5.1で導入された webpacker を利用して軽量CSSフレームワーク Spectre.css を適用する方法を残しておきます。

対象バージョン

  • macOS 10.12.5
  • Rails v5.1.1
  • Ruby v2.4.1
  • webpacker v2.0
  • webpack v2.6.1
  • node v7.10.0
  • yarn v0.24.6

前提条件

Webpackerのインストールが完了していること。

Spectre.css の適応方法

yarnでインストール

$ yarn add spectre.css

./node_modules/spectre.css/ の配下に一式インストールされます。

CSS周りの構成はwebpackerのGithubを参考に、以下のように設定します。

app/javascript/packs/application.js
...
import '../app-style'
app/javascript/app-style.sass
@import '~spectre.css/dist/spectre'

拡張子を付けるとWarningが出るので、拡張子は省いて設定します。

https://github.com/rails/webpacker/issues/461

app/views/layouts/application.html.erb
...
<%= javascript_pack_tag 'application' %>
<%= stylesheet_pack_tag 'application' %>
...

コンパイル

コンパイルには bin/webpack を使います。

$ bin/webpack

動作確認

$ bin/rails s

http://localhost:3000 にアクセスしてSpectre.cssのスタイルが適用されていれば成功です!🎉

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした