browserify-rails 3.0.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +43 -18
- data/browserify-rails.gemspec +1 -1
- data/lib/browserify-rails/version.rb +1 -1
- data/test/fixtures/use_import.out.js +3 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fc080c61fe2b627b3bbbda924d2f9c26b47bfde
|
4
|
+
data.tar.gz: b37b833f9fc8fa5bdc68880891c6d8db2c2a042c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1254b0e0c49f8e6ebeae8d1edc23f7fca5b846591b622588f7af2db5258ce9f145da0063dc8fb55e0edb34bea7b7acdb26f3df6885913961278d127a8399395a
|
7
|
+
data.tar.gz: e0a6be283f1e0f65e1df78b34a95cb68058d05c33c586267d43e8ba62c58ada5e040d5031403432b0ede5ce8e2b70578a9e14aea297bdf005e366e3be71b886a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
# browserify-rails
|
2
2
|
|
3
|
-
**If you are using react-rails or experience any issues with browserify-rails 2.x, please use the 1.5.x versions until 2.x is stabilized. Please see the issues for discussions and feel free to post your experience. The use of react-rails with browserify-rails is a bit of an anti-pattern in terms of going to CommonJS so it may never be supported. Consider using a browserify transform for React support.
|
4
|
-
|
5
|
-
[![Join the chat at https://gitter.im/browserify-rails/browserify-rails](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/browserify-rails/browserify-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6
3
|
[![Gem Version](https://badge.fury.io/rb/browserify-rails.svg)](http://badge.fury.io/rb/browserify-rails)
|
7
4
|
|
8
5
|
This library adds CommonJS module support to Sprockets (via Browserify).
|
@@ -29,7 +26,7 @@ Create `package.json` in your Rails root:
|
|
29
26
|
{
|
30
27
|
"name": "something",
|
31
28
|
"dependencies" : {
|
32
|
-
"browserify": "
|
29
|
+
"browserify": "~10.2.4",
|
33
30
|
"browserify-incremental": "^3.0.1"
|
34
31
|
},
|
35
32
|
"license": "MIT",
|
@@ -72,21 +69,20 @@ string, comment, or function.
|
|
72
69
|
## CoffeeScript
|
73
70
|
|
74
71
|
For CoffeeScript support, make sure to follow the standard rails
|
75
|
-
`.js.coffee` naming convention. You'll also need to
|
76
|
-
|
77
|
-
Add `coffeeify` as a dependency within `package.json`:
|
72
|
+
`.js.coffee` naming convention. You'll also need to add the npm
|
73
|
+
package `coffeeify` as a dependency:
|
78
74
|
|
79
75
|
```js
|
80
76
|
{
|
81
77
|
// ...
|
82
78
|
"dependencies" : {
|
83
79
|
// ...
|
84
|
-
"coffeeify": "
|
80
|
+
"coffeeify": "~0.6"
|
85
81
|
}
|
86
82
|
}
|
87
83
|
```
|
88
84
|
|
89
|
-
|
85
|
+
and configure `browserify_rails` accordingly:
|
90
86
|
|
91
87
|
```rb
|
92
88
|
config.browserify_rails.commandline_options = "-t coffeeify --extension=\".js.coffee\""
|
@@ -107,7 +103,7 @@ mentioned below into your `config/application.rb` or your environment file
|
|
107
103
|
|
108
104
|
```ruby
|
109
105
|
class My::Application < Rails::Application
|
110
|
-
#
|
106
|
+
# Specify the file paths that should be browserified. We browserify everything that
|
111
107
|
# matches (===) one of the paths. So you will most likely put lambdas
|
112
108
|
# regexes in here.
|
113
109
|
#
|
@@ -116,7 +112,7 @@ class My::Application < Rails::Application
|
|
116
112
|
# working.
|
117
113
|
config.browserify_rails.paths << /vendor\/assets\/javascripts\/module\.js/
|
118
114
|
|
119
|
-
# Environments
|
115
|
+
# Environments in which to generate source maps
|
120
116
|
#
|
121
117
|
# The default is none
|
122
118
|
config.browserify_rails.source_map_environments << "development"
|
@@ -150,6 +146,14 @@ class My::Application < Rails::Application
|
|
150
146
|
|
151
147
|
[browserify-incremental](https://github.com/jsdf/browserify-incremental) is used to cache browserification of CommonJS modules. One of the side effects is that the absolute module path is included in the emitted JavaScript. Most people do not want this for production code so browerify-incremental is current disabled for the `production` and `staging` environments. Note that counter-intuitively, browserify-incremental helps even with a single build pass of your code because typically the same modules are used multiple times. So it helps even for say asset compilation on a push to Heroku.
|
152
148
|
|
149
|
+
#### Enabling browserify-incremental in production
|
150
|
+
|
151
|
+
To enable browserify-incremental in production, add the following line to `config/environments/production.rb`:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
config.browserify_rails.use_browserifyinc = true
|
155
|
+
```
|
156
|
+
|
153
157
|
### Multiple bundles
|
154
158
|
|
155
159
|
node-browserify supports [multiple bundles](https://github.com/substack/node-browserify#multiple-bundles)
|
@@ -174,17 +178,16 @@ javascript:
|
|
174
178
|
- a_huge_library
|
175
179
|
```
|
176
180
|
|
177
|
-
Note that any valid browserify option is allowed in the YAML file but not
|
181
|
+
Note that any valid browserify option is allowed in the YAML file but not all
|
178
182
|
use cases have been considered. If your use case does not work, please open
|
179
|
-
an issue with a runnable example of the problem including your
|
180
|
-
browserify.yml file.
|
183
|
+
an issue with a runnable example of the problem including your browserify.yml file.
|
181
184
|
|
182
185
|
### Inside Isolated Engines
|
183
186
|
|
184
187
|
To make browserify-rails work inside an isolated engine, add the engine app directory to the browserify-rails paths (inside engine.rb):
|
185
188
|
|
186
189
|
```ruby
|
187
|
-
config.browserify_rails.paths <<
|
190
|
+
config.browserify_rails.paths << -> (p) { p.start_with?(Engine.root.join("app").to_s) }
|
188
191
|
```
|
189
192
|
|
190
193
|
If you wish to put the node_modules directory within the engine, you have some control over it with:
|
@@ -228,10 +231,10 @@ buildpacks that run `bundle` and `npm install` on the target machine.
|
|
228
231
|
|
229
232
|
You can easily use a browserify transform by adding it to your `package.json`, then adding the transform flag to your `application.rb`, using `config.browserify_rails.commandline_options`. For example, here is how you can add ES6 support in your app:
|
230
233
|
|
231
|
-
1. Add babelify to your `package.json` in your app's root directory, then run `npm install`
|
234
|
+
1. Add `babelify` and `babel-preset-es2015` to your `package.json` in your app's root directory, then run `npm install`
|
232
235
|
2. Add this line to your config/application.rb:
|
233
|
-
`config.browserify_rails.commandline_options = "-t babelify --
|
234
|
-
3. Create some `.es6` files and require them with `var m = require('./m.es6')` or `import m from './m.es6`
|
236
|
+
`config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 ] --extensions .es6 ]"`
|
237
|
+
3. Create some `.es6` files and require them with `var m = require('./m.es6')` or `import m from './m.es6'`
|
235
238
|
4. Restart your server, and you now have ES6 support!
|
236
239
|
|
237
240
|
|
@@ -250,6 +253,16 @@ The second method is definitely brute force but if you experience issues,
|
|
250
253
|
it is definitely worth trying before spending too much time debugging
|
251
254
|
why something that is browserified appears to not match the sources files.
|
252
255
|
|
256
|
+
### Javascript Tests
|
257
|
+
|
258
|
+
If you want to use `browserify` to process test files as well, you will
|
259
|
+
need to configure `browserify-rails` to process files in your `spec` or `test`
|
260
|
+
directories.
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
config.browserify_rails.paths << -> (p) { p.start_with?(Rails.root.join("spec/javascripts").to_s) }
|
264
|
+
```
|
265
|
+
|
253
266
|
## Acceptance Test Failures
|
254
267
|
|
255
268
|
If you have Sprockets precompile multiple JS files, each of which include
|
@@ -274,6 +287,18 @@ consume the main module. It would be nice to be able to establish this
|
|
274
287
|
relationship in the YAML file to avoid having to manually manage the require
|
275
288
|
and external entries for the involved modules.
|
276
289
|
|
290
|
+
## Alternatives
|
291
|
+
|
292
|
+
### Use webpack or browserify directly instead of the asset pipeline
|
293
|
+
|
294
|
+
Use a tool like ProcMan to kick off a webpack or browserify process to rebuild your JavaScript on change. Reference the bundle in your Rails template and away you go. With webpack, you can even use the dev server and point to the dev server port in your Rails template to load JavaScript directly from webpack (it'll block on build so you'll always get your latest code). This does require configuring webpack hot middleware to have a port (see [__webpack_hmr goes to the wrong port and fails](http://stackoverflow.com/questions/35446109/webpack-hmr-goes-to-the-wrong-port-and-fails/35446292#35446292)).
|
295
|
+
|
296
|
+
|
297
|
+
### react_on_rails
|
298
|
+
|
299
|
+
[Webpack](http://webpack.github.io/) is a popular alternative to Browserify for JavaScript tooling. A quick [Google search](https://www.google.com/search?q=browserify+vs+webpack&gws_rd=ssl) yields many articles on this topic. If you wish to use Webpack with Rails, the most popular solution is the gem [github.com/shakacode/react_on_rails](https://github.com/shakacode/react_on_rails/). While this gem focuses on React integration, it offers a solid example of how to integrate Webpack into your Rails workflow, even supporting hot-module-reloading. It also provides useful helpers to ensure that your Webpack created files are ready before tests run. A live example of these techniques can be found at [github.com/shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/).
|
300
|
+
|
301
|
+
|
277
302
|
## Contributors
|
278
303
|
|
279
304
|
* [Henry Hsu](https://github.com/hsume2)
|
data/browserify-rails.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
|
22
|
-
spec.add_runtime_dependency "railties", ">= 4.0.0", "< 5.
|
22
|
+
spec.add_runtime_dependency "railties", ">= 4.0.0", "< 5.1"
|
23
23
|
spec.add_runtime_dependency "sprockets", ">= 3.5.2"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", ">= 1.3"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/
|
1
|
+
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/Users/cvig/dev/browserify-rails/test/dummy/app/assets/javascripts/_stream_0.js":[function(require,module,exports){
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var _simple_module = require('./simple_module');
|
@@ -9,7 +9,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
9
9
|
|
10
10
|
console.log((0, _simple_module2.default)());
|
11
11
|
|
12
|
-
},{"./simple_module":"/
|
12
|
+
},{"./simple_module":"__RAILS_ROOT__/app/assets/javascripts/simple_module.js"}],"__RAILS_ROOT__/app/assets/javascripts/simple_module.js":[function(require,module,exports){
|
13
13
|
"use strict";
|
14
14
|
|
15
15
|
Object.defineProperty(exports, "__esModule", {
|
@@ -20,4 +20,4 @@ exports.default = function () {
|
|
20
20
|
return 42;
|
21
21
|
};
|
22
22
|
|
23
|
-
},{}]},{},["/
|
23
|
+
},{}]},{},["__RAILS_ROOT__/app/assets/javascripts/_stream_0.js"]);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: browserify-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Hsu, Cymen Vig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 4.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '5.
|
22
|
+
version: '5.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 4.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '5.
|
32
|
+
version: '5.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sprockets
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
255
|
version: '0'
|
256
256
|
requirements: []
|
257
257
|
rubyforge_project:
|
258
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.6.4
|
259
259
|
signing_key:
|
260
260
|
specification_version: 4
|
261
261
|
summary: 'Get the best of both worlds: Browserify + Rails = CommonJS Heaven'
|