- Notifications
You must be signed in to change notification settings - Fork 380
Integrate npm bootstrap-sass; Remove bootstrap-sass gem; Update README #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits Select commit Hold shift + click to select a range
7c6fb94
Integrate npm bootstrap-sass; Remove bootstrap-sass gem; Update README
mbreining 3856dc8
Integrate with webpack ExtractTextPlugin
mbreining 2c97240
Create webpack.common.config.js
mbreining 8e860f7
Extract duplicate code into webpack.common.config
mbreining c8fc39a
Update README
mbreining 5fb984d
Update README, take 2
mbreining 53bf847
Update README, take 3
mbreining a98f761
Add foreman gem; Update Procfile.dev and README
mbreining 8b44d97
Remove ExtractTextPlugin
mbreining c8172ea
Add bootstrap-sass gem; Use bootstrap-sass loader with local webpack …
mbreining 142e892
Add bootstrap-sprockets to js manifest
mbreining e4a2a05
Add custom bootstrap css
mbreining 09efcf9
Move bootstrap variables customization scss to webpack assets dir; Co…
mbreining 3c59196
Consolidate webpack and rails bootstrap customization file
mbreining fb28f3f
Add comments; Do another pass on README
mbreining 73d504b
Add section about Bootstrap integration
mbreining 7a314d7
Incorporte Justin's comments
mbreining f82c7ab
Overwrite default body-bg variable (instant bootstrap customization f…
mbreining e979382
Fix Readme
mbreining 223b549
Rename webpack rails config file back to webpack.rails.config.js
mbreining File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: rails s -p 4000 | ||
webpack: cd webpack && webpack -w --config webpack.rails.config.js | ||
webpack: cd webpack && $(npm bin)/webpack -w --config webpack.bundle.config.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
| @@ -8,88 +8,153 @@ Full tutorial can be found at: [Fast Rich Client Rails Development With Webpack | |
| ||
# Motivation | ||
| ||
1. Enable development of a JS client separate from Rails. | ||
2. Enable easily retrofitting such a JS framework into an existing Rails app. | ||
3. Enable the use of the JavaScript es6 transpiler. | ||
4. Enable easily using npm modules with a Rails application. | ||
In no particular order: | ||
- Enable development of a JS client independently from Rails. | ||
- Easily enable use of npm modules with a Rails application. | ||
- Easily enable retrofitting such a JS framework into an existing Rails app. | ||
- Enable the use of the JavaScript ES6 transpiler. | ||
| ||
# Example of the following technologies: | ||
# Technologies involved | ||
| ||
1. react | ||
2. react-bootstrap | ||
3. webpack with hot-reload | ||
4. es6-loader (es6 transpiler) | ||
5. Simultaneously working with Rails 4.2 | ||
6. Deployable to Heroku | ||
1. React 0.11 (for front-end app) | ||
2. React-bootstrap 0.12 | ||
3. Webpack with hot-reload 1.4 (for local dev) | ||
4. ES6 transpiler (es6-loader) 0.2 | ||
5. Rails 4.2 (for backend app) | ||
6. Heroku (for deployment) | ||
| ||
# Running without Rails using Hot Reload | ||
# Javascript development without Rails using Hot Module Replacement (HMR) | ||
| ||
Setup node and run the node server. | ||
| ||
``` | ||
npm install | ||
cd webpack && node server.js | ||
``` | ||
| ||
Point browser to [http://0.0.0.0:3000](). | ||
Point your browser to [http://0.0.0.0:3000](). | ||
| ||
| ||
Save a change to a JSX file and see it update immediately in the browser! Note, | ||
any browser state still exists, such as what you've typed in the comments box. | ||
That's totally different than "Live Reload" which refreshes the browser. | ||
That's totally different than [Live Reload](http://livereload.com/) which refreshes | ||
the browser. | ||
| ||
# Rails integration | ||
| ||
## Build JS/CSS bundles | ||
Run this command to have webpack build the JS/CSS bundles and have them saved in the Rails | ||
asset pipeline (app/assets). | ||
The Webpack ExtractTextPlugin can optionally be used to extract the CSS out of | ||
the JS bundle. The following bundles would then be generated: | ||
- rails-bundle.js which gets saved to app/assets/javascripts | ||
- bootstrap-and-customizations.css which gets saved in app/assets/stylesheets | ||
Observe how the bundles are automatically re-generated whenever your JSX changes. | ||
| ||
# Rails | ||
``` | ||
cd webpack | ||
webpack -w --config webpack.rails.config.js | ||
``` | ||
| ||
Make sure to invoke your local copy of the webpack executable as opposed | ||
to any globally installed webpack. | ||
See https://github.com/webpack/extract-text-webpack-plugin/blob/master/example/webpack.config.js | ||
If in doubt, run the following command: | ||
``` | ||
$(npm bin)/webpack -w --config webpack.rails.config.js | ||
``` | ||
| ||
## Run Rails server | ||
| ||
Once the JS/CSS bundled have been generated into the Rails asset pipeline, you can start | ||
the Rails server. | ||
| ||
``` | ||
cd <rails_project_name> | ||
bundle install | ||
rake db:setup | ||
rails s -p 4000 | ||
``` | ||
Point browser to [http://0.0.0.0:4000](). | ||
Point your browser to [http://0.0.0.0:4000](). | ||
| ||
It's important to run the rails server on different port than the node server. | ||
It's important to run the Rails server on a different port than the node server. | ||
| ||
## Automatically Building the rails-bundle.js | ||
Run this command to automatically build the rails-bundle.js file in the | ||
javascript directory whenever your jsx files change. | ||
# Webpack configuration | ||
- `webpack.hot.config.js`: Used by server.js to run the demo express server. | ||
- `webpack.rails.config.js`: Used to generate the Rails bundles. | ||
- `webpack.common.config.js`: Common configuration file to minimize code duplication. | ||
| ||
``` | ||
cd webpack | ||
webpack -w --config webpack.rails.config.js | ||
``` | ||
# Bootstrap integration | ||
Notice that Bootstrap Sass is installed as both a gem and an npm package. | ||
When running the Rails app, the bootstrap-sass gem assets are loaded directly | ||
through the asset pipeline without passing through Webpack. | ||
See app/assets/application.css.scss. | ||
On the other hand when running the Webpack dev server, the bootrap-sass npm | ||
assets are loaded through Webpack (with help of the bootstrap-sass-loader). | ||
See webpack/webpack.hot.config.js. | ||
| ||
| ||
Bootstrap can be customized by hand-picking which modules to load and/or overwriting | ||
some of the Sass variables defined by the frameworks. | ||
| ||
## Bootstrap modules customization | ||
| ||
If you are not using all the Bootstrap modules then you'll likely want to customize | ||
it to avoid loading unused assets. This customization is done in separate files | ||
for the Rails app versus the Webpack dev server so it's important to keep these | ||
in-sync as you develop your app in parallel using the Rails and the Webpack HMR | ||
environments. | ||
| ||
- Rails Bootstrap customization file: app/assets/stylesheets/_bootstrap-custom.scss | ||
- Webpack HMR Bootstrap customization file: webpack/bootstrap-sass.config.js | ||
| ||
## Bootstrap variables customization | ||
| ||
# Webpack Configuration | ||
`webpack.hot.config.js`: Used by server.js to run the demo server. | ||
`webpack.rails.config.js`: Used to generate the rails-bundle.js file | ||
If you need to customize some of the Sass variables defined in Bootstrap you | ||
can do so by overwriting these variables in a separate file and have it loaded | ||
before other Bootstrap modules. | ||
| ||
# Notes on Rails Assets | ||
To avoid duplicating this customization between Rails and Webpack HMR, | ||
this custom code has been consolidated under Webpack in | ||
webpack/assets/stylesheets/_bootstrap-variables-customization.scss and the | ||
webpack/assets/stylesheets directory added to the Rails asset pipeline | ||
search path. See config config/application.rb. Keep that in mind as you | ||
customize the Bootstrap Sass variables. | ||
| ||
# Notes on Rails assets | ||
## Javascript | ||
The `webpack.rails.config.js` file generates rails-bundle.js which is included | ||
The `webpack.rails.config.js` file generates rails-bundle.js which is then included | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may consider changing the name of this file to webpack-bundle.js, just so it's totally clear where it's coming from...rails doesn't really have much meaning in this context. | ||
by the Rails asset pipeline. | ||
| ||
## Sass and images | ||
1. The Webpack server loads the images from the **symlink** of of the | ||
1. The Webpack server loads the images from the **symlink** of the | ||
app/assets/images directory. | ||
2. Since the images are not moved, Rails loads images via the normal asset | ||
pipeline features. | ||
3. The `image-url` sass helper takes care of mapping the correct directories for | ||
images. The image directory for the webpack server is configured by this | ||
line: | ||
| ||
``` | ||
{ test: /\.scss$/, loader: "style!css!sass?outputStyle=expanded&imagePath=/assets/images"} | ||
``` | ||
| ||
# Process management | ||
Run the following command in your development environment to invoke both Webpack and Rails. | ||
``` | ||
bundle exec foreman start -f Procfile.dev | ||
``` | ||
| ||
# Source Maps | ||
They work for both Rails and the Webpack Server! | ||
| ||
# Deploying to Heroku | ||
| ||
In order to deploy to heroku, you'll need run this command once to set a custom | ||
In order to deploy to heroku, you'll need to run this command once to set a custom | ||
buildpack: | ||
| ||
``` | ||
heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git | ||
``` | ||
| ||
This runs the two buildpacks in the `.buildpacks` directory. | ||
| ||
# TO DO | ||
1. (Optionally) integrate twitter bootstrap assets into webpack build with way | ||
to configure same options for Rails and Webpack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Customizations - needs to be imported first! | ||
@import "bootstrap-variables-customization"; | ||
| ||
// Core variables and mixins | ||
@import "bootstrap/variables"; | ||
@import "bootstrap/mixins"; | ||
| ||
// Reset and dependencies | ||
@import "bootstrap/normalize"; | ||
@import "bootstrap/print"; | ||
@import "bootstrap/glyphicons"; | ||
| ||
// Core CSS | ||
@import "bootstrap/scaffolding"; | ||
@import "bootstrap/type"; | ||
@import "bootstrap/code"; | ||
@import "bootstrap/grid"; | ||
@import "bootstrap/tables"; | ||
@import "bootstrap/forms"; | ||
@import "bootstrap/buttons"; | ||
| ||
// Components | ||
@import "bootstrap/component-animations"; | ||
@import "bootstrap/dropdowns"; | ||
@import "bootstrap/button-groups"; | ||
@import "bootstrap/input-groups"; | ||
@import "bootstrap/navs"; | ||
@import "bootstrap/navbar"; | ||
@import "bootstrap/breadcrumbs"; | ||
@import "bootstrap/pagination"; | ||
@import "bootstrap/pager"; | ||
@import "bootstrap/labels"; | ||
@import "bootstrap/badges"; | ||
//@import "bootstrap/jumbotron"; // excluding as an example | ||
@import "bootstrap/thumbnails"; | ||
@import "bootstrap/alerts"; | ||
//@import "bootstrap/progress-bars"; // excluding as an example | ||
@import "bootstrap/media"; | ||
@import "bootstrap/list-group"; | ||
@import "bootstrap/panels"; | ||
@import "bootstrap/responsive-embed"; | ||
@import "bootstrap/wells"; | ||
@import "bootstrap/close"; | ||
| ||
// Components w/ JavaScript | ||
@import "bootstrap/modals"; // excluding as an example | ||
@import "bootstrap/tooltip"; | ||
@import "bootstrap/popovers"; | ||
@import "bootstrap/carousel"; // excluding as an example | ||
| ||
// Utility classes | ||
@import "bootstrap/utilities"; | ||
@import "bootstrap/responsive-utilities"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
@import "bootstrap-sprockets"; | ||
@import "bootstrap"; | ||
@import "../../../webpack/assets/stylesheets/test-stylesheet"; | ||
@import "../../../webpack/assets/stylesheets/test-sass-stylesheet"; | ||
| ||
@import "bootstrap-sprockets"; | ||
@import "bootstrap-custom"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will change this shortly, but this can be the next PR