Skip to content

Instantly share code, notes, and snippets.

@bazzel
Last active December 27, 2018 13:21
Show Gist options
  • Save bazzel/49caa9c6ad3cc1f184194661e28223ae to your computer and use it in GitHub Desktop.
Save bazzel/49caa9c6ad3cc1f184194661e28223ae to your computer and use it in GitHub Desktop.
Ruby on Rails - Material Design

See also https://material.io/

$ rails new my-app --webpack
$ bundle --binstubs

config/webpack/loaders/sass.js

// https://github.com/rails/webpacker/issues/454#issuecomment-370158350
const cssLoader = require('@rails/webpacker/package/rules/css')
const cloneDeep = require('lodash/fp/cloneDeep')
const deepMerge = require('@rails/webpacker/package/utils/deep_merge')

let sassLoader = cloneDeep(cssLoader)
module.exports = deepMerge(sassLoader, {
  test: /\.(scss|sass)$/i,
  use: [{
    loader: 'sass-loader',
    options: {
      includePaths: ['node_modules'],
      sourceMap: true,
    },
  }]
})

config/webpack/environment.js

...
const sass = require('./loaders/sass')

environment.loaders.append('sass', sass)
...

app/javascript/packs/styles.scss

@import "~@material/button/mdc-button";

.foo-button {
  @include mdc-button-ink-color(teal);
  @include mdc-states(teal);
}
$ bin/rails g controller welcome index

config/routes.rb

root 'welcome#index'

app/views/layouts/application.html.erb

<%= javascript_pack_tag 'styles', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
$ bin/rails s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment