Skip to content

Commit 7a314d7

Browse files
committed
Incorporte Justin's comments
1 parent 73d504b commit 7a314d7

9 files changed

+50
-109
lines changed

Procfile.dev

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
web: rails s -p 4000
2-
webpack: cd webpack && $(npm bin)/webpack -w --config webpack.rails.config.js
2+
webpack: cd webpack && $(npm bin)/webpack -w --config webpack.bundle.config.js

README.md

+34-14
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ In no particular order:
1919
1. React 0.11 (for front-end app)
2020
2. React-bootstrap 0.12
2121
3. Webpack with hot-reload 1.4 (for local dev)
22-
4. Webpack ExtractTextPlugin (to extract CSS out of JS bundle)
2322
4. ES6 transpiler (es6-loader) 0.2
2423
5. Rails 4.2 (for backend app)
2524
6. Heroku (for deployment)
@@ -35,13 +34,6 @@ cd webpack && node server.js
3534

3635
Point browser to [http://0.0.0.0:3000]().
3736

38-
Make sure to invoke your local copy of the webpack executable as opposed
39-
to any globally installed webpack.
40-
See https://github.com/webpack/extract-text-webpack-plugin/blob/master/example/webpack.config.js
41-
If in doubt, run the following command:
42-
```
43-
$(npm bin)/webpack --config webpack.hot.config.js
44-
```
4537

4638
Save a change to a JSX file and see it update immediately in the browser! Note,
4739
any browser state still exists, such as what you've typed in the comments box.
@@ -61,7 +53,15 @@ Observe how the bundles are automatically re-generated whenever your JSX changes
6153

6254
```
6355
cd webpack
64-
webpack -w --config webpack.rails.config.js
56+
webpack -w --config webpack.bundle.config.js
57+
```
58+
59+
Make sure to invoke your local copy of the webpack executable as opposed
60+
to any globally installed webpack.
61+
See https://github.com/webpack/extract-text-webpack-plugin/blob/master/example/webpack.config.js
62+
If in doubt, run the following command:
63+
```
64+
$(npm bin)/webpack -w --config webpack.bundle.config.js
6565
```
6666

6767
## Run Rails server
@@ -81,7 +81,7 @@ It's important to run the Rails server on a different port than the node server.
8181

8282
# Webpack configuration
8383
- `webpack.hot.config.js`: Used by server.js to run the demo express server.
84-
- `webpack.rails.config.js`: Used to generate the Rails bundles.
84+
- `webpack.bundle.config.js`: Used to generate the Rails bundles.
8585
- `webpack.common.config.js`: Common configuration file to minimize code duplication.
8686

8787
# Bootstrap integration
@@ -94,16 +94,36 @@ assets are loaded through Webpack (with help of the bootstrap-sass-loader).
9494
See webpack/webpack.hot.config.js.
9595

9696

97-
To avoid duplicating any Bootstrap customization between Rails and Webpack,
98-
all Bootstrap customizations have been consolidated under Webpack in
97+
Bootstrap can be customized by hand-picking which modules to load and/or overwriting
98+
some of the Sass variables defined by the frameworks.
99+
100+
## Bootstrap modules customization
101+
102+
If you are not using all the Bootstrap modules then you'll likely want to customize
103+
it to avoid loading unused assets. This customization is done in separate files
104+
for the Rails app versus the Webpack dev server so it's important to keep these
105+
in-sync as you develop your app in parallel using the Rails and the Webpack HMR
106+
environments.
107+
108+
- Rails Bootstrap customization file: app/assets/stylesheets/_bootstrap-custom.scss
109+
- Webpack HMR Bootstrap customization file: webpack/bootstrap-sass.config.js
110+
111+
## Bootstrap variables customization
112+
113+
If you need to customize some of the Sass variables defined in Bootstrap you
114+
can do so by overwriting these variables in a separate file and have it loaded
115+
before other Bootstrap modules.
116+
117+
To avoid duplicating this customization between Rails and Webpack HMR,
118+
this custom code has been consolidated under Webpack in
99119
webpack/assets/stylesheets/_bootstrap-variables-customization.scss and the
100120
webpack/assets/stylesheets directory added to the Rails asset pipeline
101121
search path. See config config/application.rb. Keep that in mind as you
102-
need to customize Bootstrap.
122+
customize the Bootstrap Sass variables.
103123

104124
# Notes on Rails assets
105125
## Javascript
106-
The `webpack.rails.config.js` file generates rails-bundle.js which is then included
126+
The `webpack.bundle.config.js` file generates rails-bundle.js which is then included
107127
by the Rails asset pipeline.
108128

109129
## Sass and images

webpack/bootstrap-sass.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// IMPORTANT: Make sure to keep the customizations defined in this file
2+
// in-sync with the ones defined in app/assets/stylesheets/_bootstrap-custom.scss.
3+
14
module.exports = {
25
bootstrapCustomizations: "./assets/stylesheets/_bootstrap-variables-customization.scss",
36
mainSass: "./_main.scss",

webpack/bootstrap-sass.extract-text.config.js

-75
This file was deleted.

webpack/scripts/rails_only.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @jsx React.DOM */
22

3-
// This could be done here, but instead it's done in the webpack.rails.config.js file
3+
// This could be done here, but instead it's done in the webpack.bundle.config.js file
44
// Showing this for example purposes
55
// require("expose?$!jquery");
66
// require("expose?jQuery!jquery");

webpack/scripts/webpack_only.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// These are only loaded by the webpack dev server
22

33
require("test-stylesheet.css");
4-
require("test-sass-stylesheet.scss"); // test out sass
4+
// Test out Sass.
5+
// Note that any sass in here cannot use the variables and mixins
6+
// defined in the boostrap customizations file.
7+
require("test-sass-stylesheet.scss");
58

69
require("expose?$!jquery");
710
require("expose?jQuery!jquery");

webpack/webpack.rails.config.js renamed to webpack/webpack.bundle.config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Run like this:
2-
// cd webpack && $(npm bin)/webpack -w --config webpack.hot.config.js
2+
// cd webpack && $(npm bin)/webpack -w --config webpack.bundle.config.js
3+
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
34

45
var config = require("./webpack.common.config");
56

@@ -19,7 +20,7 @@ module.exports = config;
1920
var devBuild = (typeof process.env["BUILDPACK_URL"]) === "undefined";
2021
if (devBuild) {
2122
console.log("Webpack dev build for Rails");
22-
//module.exports.devtool = "eval-source-map";
23+
module.exports.devtool = "eval-source-map";
2324
} else {
2425
console.log("Webpack production build for Rails");
2526
}

webpack/webpack.common.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// Common webpack configuration used by webpack.hot.config and webpack.rails.config.
1+
// Common webpack configuration used by webpack.hot.config and webpack.bundle.config.
22

33
var path = require("path");
44

55
module.exports = {
6-
devtool: "eval-source-map",
76
context: __dirname, // the project dir
87
entry: [ "./assets/javascripts/example" ],
98
// In case you wanted to load jQuery from the CDN, this is how you would do it:

webpack/webpack.hot.config.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
// Run like this:
2-
// cd webpack && $(npm bin)/webpack -w --config webpack.hot.config.js
3-
// or:
42
// cd webpack && node server.js
53

64
var config = require("./webpack.common.config");
75
var webpack = require("webpack");
8-
//var ExtractTextPlugin = require("extract-text-webpack-plugin");
96

10-
// Add the following entries as appropriate:
11-
// "bootstrap-sass-loader" -> all bootstrap assets
12-
// "bootstrap-sass!./bootstrap-sass.config.js" -> custom bootstrap
13-
// "bootstrap-sass!./bootstrap-sass.extract-text.config.js" -> custom bootstrap w/ ExtractTextPlugin
147
config.entry.push("webpack-dev-server/client?http://localhost:3000",
158
"webpack/hot/dev-server",
169
"./scripts/webpack_only",
17-
"bootstrap-sass!./bootstrap-sass.config.js");
18-
//"bootstrap-sass!./bootstrap-sass.extract-text.config.js");
10+
"bootstrap-sass!./bootstrap-sass.config.js"); // custom bootstrap
11+
//"bootstrap-sass-loader" -> all bootstrap assets
1912
config.output = { filename: "express-bundle.js", // this file is served directly by webpack
2013
path: __dirname };
21-
//config.module.loaders.push(
22-
// { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
23-
//);
2414
config.plugins = [ new webpack.HotModuleReplacementPlugin() ];
25-
//new ExtractTextPlugin("bootstrap-and-customizations.css") ];
15+
config.devtool = "eval-source-map";
2616
module.exports = config;

0 commit comments

Comments
 (0)