Skip to content

Commit 98eb9d5

Browse files
committed
Transfer all assets management to webpack, switch to CSS Modules
1 parent dc6df39 commit 98eb9d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+376
-444
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ vendor/ruby
2727
.ruby-gemset
2828

2929
# Generated js bundles
30-
/app/assets/javascripts/generated/*
30+
/app/assets/webpack/
3131

3232
# Rubymine/IntelliJ
3333
.idea

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
web: rails s
2-
client: sh -c 'rm app/assets/javascripts/generated/* || true && cd client && npm run build:dev:client'
2+
client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev:client'
33
server: sh -c 'cd client && npm run build:dev:server'
44
hot: sh -c 'cd client && npm start'

app/assets/javascripts/application.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
1111
// about supported directives.
1212

13-
// CRITICAL that generated/vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks since it is
14-
// exposing jQuery and jQuery-ujs
15-
//= require generated/vendor-bundle
16-
//= require generated/app-bundle
13+
// These assets are located in app/assets/webpack directory
14+
// CRITICAL that webpack/vendor-bundle must be BEFORE turbolinks
15+
// since it is exposing jQuery and jQuery-ujs
16+
//= require vendor-bundle
17+
//= require app-bundle
1718

18-
// Next two depend on jQuery
19+
// Next one depend on jQuery
1920
//= require turbolinks
20-
//= require bootstrap-sprockets
2121

2222
//= require react_on_rails
2323

app/assets/stylesheets/_bootstrap-custom.scss

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
// This variable $rails is used by bootstrap-custom so that fonts are loaded slightly differently
2-
// with Rails vs. the Webpack Dev Server
3-
$rails: true;
4-
5-
// Those scss files are located under client/assets/stylesheets,
6-
// which has been added to the Rails asset pipeline search path.
7-
// See config/application.rb.
8-
@import 'bootstrap-custom';
9-
@import 'test-stylesheet';
10-
@import 'test-sass-stylesheet';
11-
12-
@import 'bootstrap-sprockets';
1+
// These assets are located in app/assets/webpack directory
2+
@import 'vendor-bundle';
3+
@import 'app-bundle';

app/assets/stylesheets/scaffolds.css.scss

Lines changed: 0 additions & 77 deletions
This file was deleted.

client/.bootstraprc

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
# Output debugging info
3+
# loglevel: debug
4+
5+
# Major version of Bootstrap: 3 or 4
6+
bootstrapVersion: 3
7+
8+
# Webpack loaders, order matters
9+
styleLoaders:
10+
- style
11+
- css
12+
- sass
13+
14+
# Extract styles to stand-alone css file
15+
# Different settings for different environments can be used,
16+
# It depends on value of NODE_ENV environment variable
17+
# This param can also be set in webpack config:
18+
# entry: 'bootstrap-loader/extractStyles'
19+
extractStyles: false
20+
# env:
21+
# development:
22+
# extractStyles: false
23+
# production:
24+
# extractStyles: true
25+
26+
# Customize Bootstrap variables that get imported before the original Bootstrap variables.
27+
# Thus original Bootstrap variables can depend on values from here. All the bootstrap
28+
# variables are configured with !default, and thus, if you define the variable here, then
29+
# that value is used, rather than the default. However, many bootstrap variables are derived
30+
# from other bootstrap variables, and thus, you want to set this up before we load the
31+
# official bootstrap versions.
32+
# For example, _variables.scss contains:
33+
# $input-color: $gray !default;
34+
# This means you can define $input-color before we load _variables.scss
35+
preBootstrapCustomizations: ./app/assets/styles/bootstrap-pre-customizations.scss
36+
37+
# This gets loaded after bootstrap/variables is loaded and before bootstrap is loaded.
38+
# A good example of this is when you want to override a bootstrap variable to be based
39+
# on the default value of bootstrap. This is pretty specialized case. Thus, you normally
40+
# just override bootrap variables in preBootstrapCustomizations so that derived
41+
# variables will use your definition.
42+
#
43+
# For example, in _variables.scss:
44+
# $input-height: (($font-size-base * $line-height) + ($input-padding-y * 2) + ($border-width * 2)) !default;
45+
# This means that you could define this yourself in preBootstrapCustomizations. Or you can do
46+
# this in bootstrapCustomizations to make the input height 10% bigger than the default calculation.
47+
# Thus you can leverage the default calculations.
48+
# $input-height: $input-height * 1.10;
49+
# bootstrapCustomizations: ./app/assets/styles/bootstrap-customizations.scss
50+
51+
# Import your custom styles here. You have access to all the bootstrap variables. If you require
52+
# your sass files separately, you will not have access to the bootstrap variables, mixins, clases, etc.
53+
# Usually this endpoint-file contains list of @imports of your application styles.
54+
# But since we use CSS Modules, we don't need it - every module gets imported from JS component.
55+
# appStyles: ./app/styles/app.scss
56+
57+
### Bootstrap styles
58+
styles:
59+
60+
# Mixins
61+
mixins: true
62+
63+
# Reset and dependencies
64+
normalize: true
65+
print: true
66+
glyphicons: true
67+
68+
# Core CSS
69+
scaffolding: true
70+
type: true
71+
code: true
72+
grid: true
73+
tables: true
74+
forms: true
75+
buttons: true
76+
77+
# Components
78+
component-animations: true
79+
dropdowns: true
80+
button-groups: true
81+
input-groups: true
82+
navs: true
83+
navbar: true
84+
breadcrumbs: true
85+
pagination: true
86+
pager: true
87+
labels: true
88+
badges: true
89+
jumbotron: true
90+
thumbnails: true
91+
alerts: true
92+
progress-bars: true
93+
media: true
94+
list-group: true
95+
panels: true
96+
wells: true
97+
responsive-embed: true
98+
close: true
99+
100+
# Components w/ JavaScript
101+
modals: true
102+
tooltip: true
103+
popovers: true
104+
carousel: true
105+
106+
# Utility classes
107+
utilities: true
108+
responsive-utilities: true
109+
110+
### Bootstrap scripts
111+
scripts:
112+
transition: true
113+
alert: true
114+
button: true
115+
carousel: true
116+
collapse: true
117+
dropdown: true
118+
modal: true
119+
tooltip: true
120+
popover: true
121+
scrollspy: true
122+
tab: true
123+
affix: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Defining application SASS variables in stand-alone file,
2+
// so we can use them in bootstrap-loader and CSS Modules via sass-resources-loader
3+
$body-bg: #eff8fb; // background w/ character
4+
$navbar-default-bg: #ffffe0; // fancy yellow navbar
5+
$font-size-base: 15px; // make it bigger!
6+
$font-family-sans-serif: 'OpenSans-Light'; // apply custom font
7+
8+
// It will be used in SASS components imported as CSS Modules
9+
$comment-author-color: blue;
10+
$comment-text-color: purple;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// These variables get loaded BEFORE Bootstrap thus overriding them in Bootstrap.
2+
@import "./app-variables";
3+
4+
// This path is relative to this file!
5+
$fonts-url-path: "../fonts";
6+
7+
@font-face {
8+
font-family: "OpenSans-Light";
9+
src: url("#{$fonts-url-path}/OpenSans-Light.ttf") format("truetype");
10+
}

client/app/bundles/Comments/components/CommentBox/CommentBox.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import React, { PropTypes } from 'react';
33
import CommentForm from './CommentForm/CommentForm';
44
import CommentList from './CommentList/CommentList';
55

6+
import './CommentBox.scss';
7+
68
export default class CommentBox extends React.Component {
79

810
static propTypes = {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:global {
2+
3+
.element-enter {
4+
opacity: 0.01;
5+
6+
&.element-enter-active {
7+
opacity: 1;
8+
transition: opacity 0.5s ease-in;
9+
}
10+
}
11+
12+
.element-leave {
13+
opacity: 1;
14+
15+
&.element-leave-active {
16+
opacity: 0.01;
17+
transition: opacity 0.5s ease-in;
18+
}
19+
}
20+
21+
}

client/app/bundles/Comments/components/CommentBox/CommentList/Comment/Comment.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { PropTypes } from 'react';
22
import marked from 'marked';
33

4+
import css from './Comment.scss';
5+
46
export default class Comment extends React.Component {
57

68
static propTypes = {
@@ -13,8 +15,8 @@ export default class Comment extends React.Component {
1315
const rawMarkup = marked(text, { gfm: true, sanitize: true });
1416

1517
return (
16-
<div className="comment">
17-
<h2 className="comment-author">
18+
<div className={css.comment}>
19+
<h2 className={css.commentAuthor}>
1820
{author}
1921
</h2>
2022
<span
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.comment {
2+
3+
.commentAuthor {
4+
color: $comment-author-color; // <--- Loaded via sass-resources-loader
5+
}
6+
7+
p {
8+
color: $comment-text-color; // <-- This one also
9+
}
10+
11+
}

0 commit comments

Comments
 (0)