@@ -13,43 +13,55 @@ Full tutorial can be found at: [Fast Rich Client Rails Development With Webpack
13
13
3 . Enable the use of the JavaScript es6 transpiler.
14
14
4 . Enable easily using npm modules with a Rails application.
15
15
16
- # Example of the following technologies:
16
+ # Example of the following technologies
17
17
18
- 1 . react
19
- 2 . react-bootstrap
20
- 3 . webpack with hot-reload
18
+ 1 . React
19
+ 2 . React-bootstrap
20
+ 3 . Webpack with hot-reload
21
+ 4 . Webpack ExtractTextPlugin
21
22
4 . es6-loader (es6 transpiler)
22
23
5 . Simultaneously working with Rails 4.2
23
24
6 . Deployable to Heroku
24
25
25
- # Running without Rails using Hot Reload
26
+ # Running without Rails using Module Hot Replacement
26
27
27
28
Setup node and run the node server.
29
+
28
30
```
29
31
npm install
30
- cd webpack && node server.js
32
+ cd webpack && webpack --config webpack.hot.config.js
33
+ node server.js
31
34
```
32
35
33
36
Point browser to [ http://0.0.0.0:3000 ] ( ) .
34
37
38
+ Note: 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
+
35
42
Save a change to a JSX file and see it update immediately in the browser! Note,
36
43
any browser state still exists, such as what you've typed in the comments box.
37
44
That's totally different than "Live Reload" which refreshes the browser.
38
45
39
- # Rails
46
+ # Running with Rails
40
47
41
- ## Automatically building the rails-bundle.js
42
- Run this command to automatically build the rails-bundle.js file in the
43
- javascript directory whenever your jsx files change.
48
+ ## Build Rails bundles
49
+ Run this command to have webpack build the Rails bundles in the Rails
50
+ asset pipeline.
51
+ Note that the Webpack ExtractTextPlugin is used so that two bundles are generated:
52
+ - rails-bundle.js which gets copied to app/assets/javascripts
53
+ - bootstrap-and-customizations.css which gets copied in app/assets/stylesheet
54
+ Observe how the bundles are automatically re-generated whever your JSX changes.
44
55
45
56
```
46
57
cd webpack
47
58
webpack -w --config webpack.rails.config.js
48
59
```
49
60
50
- ## Run Rails
61
+ ## Run Rails server
51
62
52
63
```
64
+ cd <rails_project_name>
53
65
bundle install
54
66
rake db:setup
55
67
rails s -p 4000
@@ -58,17 +70,18 @@ Point browser to [http://0.0.0.0:4000]().
58
70
59
71
It's important to run the rails server on different port than the node server.
60
72
61
- # Webpack Configuration
62
- ` webpack.hot.config.js ` : Used by server.js to run the demo server.
63
- ` webpack.rails.config.js ` : Used to generate the rails-bundle.js file
73
+ # Webpack configuration files
74
+ - ` webpack.hot.config.js ` : Used by server.js to run the demo express server.
75
+ - ` webpack.rails.config.js ` : Used to generate the Rails bundles.
76
+ - ` webpack.common.config.js ` : Common configuration file to minimize code duplication.
64
77
65
- # Notes on Rails Assets
78
+ # Notes on Rails assets
66
79
## Javascript
67
- The ` webpack.rails.config.js ` file generates rails-bundle.js which is included
80
+ The ` webpack.rails.config.js ` file generates rails-bundle.js which is then included
68
81
by the Rails asset pipeline.
69
82
70
83
## Sass and images
71
- 1 . The Webpack server loads the images from the ** symlink** of of the
84
+ 1 . The Webpack server loads the images from the ** symlink** of the
72
85
app/assets/images directory.
73
86
2 . Since the images are not moved, Rails loads images via the normal asset
74
87
pipeline features.
@@ -91,7 +104,3 @@ heroku config:add BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-mult
91
104
```
92
105
93
106
This runs the two buildpacks in the ` .buildpacks ` directory.
94
-
95
- # TO DO
96
- 1 . (Optionally) integrate twitter bootstrap assets into webpack build with way
97
- to configure same options for Rails and Webpack.
0 commit comments