Skip to content

Commit a8ca647

Browse files
committed
Merge pull request #88 from shakacode/move-jquery_ujs-under-npm
Move jQuery and jQuery-ujs under /client and npm
2 parents 9017941 + 421cef2 commit a8ca647

File tree

8 files changed

+293
-292
lines changed

8 files changed

+293
-292
lines changed

Gemfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ gem "coffee-rails"
1818
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
1919
# gem "therubyracer", platforms: :ruby
2020

21-
# Use jquery as the JavaScript library
22-
gem "jquery-rails"
21+
# jquery as the JavaScript library has been moved under /client and managed by npm.
22+
# It is critical to not include any of the jquery gems when following this pattern or
23+
# else you might have multiple jQuery versions.
24+
2325
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
2426
gem "turbolinks"
2527
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder

Gemfile.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ GEM
108108
jbuilder (2.3.1)
109109
activesupport (>= 3.0.0, < 5)
110110
multi_json (~> 1.2)
111-
jquery-rails (4.0.4)
112-
rails-dom-testing (~> 1.0)
113-
railties (>= 4.2.0)
114-
thor (>= 0.14, < 2.0)
115111
json (1.8.3)
116112
kgio (2.9.3)
117113
launchy (2.4.3)
@@ -275,7 +271,6 @@ DEPENDENCIES
275271
factory_girl_rails
276272
foreman
277273
jbuilder
278-
jquery-rails
279274
launchy
280275
pg
281276
phantomjs

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ Be sure to see [assets.rake](https://github.com/shakacode/react-webpack-rails-tu
173173
The `webpack.rails.config.js` file generates client-bundle.js which is then included
174174
by the Rails asset pipeline.
175175

176+
##jQuery with Rails and Webpack
177+
jQuery and jQuery-ujs are not required within `app/assets/javascript/application.js`
178+
and have been moved under`/client` and managed by npm. The modules are exposed via entry point
179+
by `webpack.common.config.js`.
180+
181+
In `application.js`, it's critical that any libraries that depend on jQuery come after the inclusion
182+
of the Webpack bundle, such as the twitter bootstrap javascript.
183+
184+
Please refer to [Considerations for jQuery with Rails and Webpack](http://forum.railsonmaui.com/t/considerations-for-jquery-with-rails-and-webpack/344) for further info.
185+
186+
176187
## Sass and images
177188
1. The Webpack server loads the images from the **symlink** of the
178189
`app/assets/images` directory.

app/assets/javascripts/application.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
//
1010
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
1111
// about supported directives.
12-
//
13-
//= require jquery
14-
//= require jquery_ujs
15-
16-
//= require bootstrap-sprockets
17-
18-
// Important to import jquery_ujs before rails-bundle as that patches jquery xhr to use the authenticity token!
1912

13+
// Need to be on top to allow Poltergeist test to work with React.
2014
//= require es5-shim/es5-shim
15+
16+
// It is important that generated/client-bundle must be before bootstrap since it is exposing jQuery and jQuery-ujs
2117
//= require generated/client-bundle
18+
//= require bootstrap-sprockets
2219
//= require turbolinks

0 commit comments

Comments
 (0)