browserify-rails 4.2.0 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +10 -0
- data/README.md +50 -6
- data/browserify-rails.gemspec +1 -1
- data/lib/browserify-rails/browserify_processor.rb +5 -5
- data/lib/browserify-rails/version.rb +1 -1
- data/test/compilation_test.rb +1 -0
- data/test/dummy/app/assets/config/manifest.js +1 -0
- data/test/dummy/package-lock.json +2347 -0
- data/test/fixtures/application.changed.out.js +1 -1
- data/test/fixtures/application.foo_changed.out.js +1 -1
- data/test/fixtures/application.node_test_package_changed.out.js +2 -2
- data/test/fixtures/application.out.js +1 -1
- data/test/fixtures/js-with-sourcemap-url.out.js +2 -2
- data/test/fixtures/main.out.js +1 -1
- data/test/fixtures/mocha.js +1 -1
- data/test/fixtures/node_path_based_require.out.js +1 -1
- data/test/fixtures/plain.out.js +1 -1
- data/test/fixtures/secondary.out.js +1 -1
- data/test/fixtures/use_import.out.js +1 -1
- metadata +7 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cad940efd5616a2cd49abc09b559bee472df4ded7c308a21975a2a265b01b74a
|
4
|
+
data.tar.gz: 7bbdcb45126644fdf62358154f1b5bd04712e5ed01caefbc6555500991b1bef6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b1be15ad5163e9657e6708134ca7420fbc8b7cad8b4697965424a0d92ced3d639f4cbcb0803fa75e06a32a3c3d542c7a4ecf97f421c308a5440fe4c120ff711
|
7
|
+
data.tar.gz: 40ace03ac65f0a529925fda364c029046b53347baaf3ada01dd69a2795cc945d1da8e5b59390087a07c406f19a9b27f539e42b173afcea9333c853389764173c
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file going forward.
|
3
3
|
|
4
|
+
## [4.4.0] - 2020-05-16
|
5
|
+
- sprockets 4 support thanks to dkamenka
|
6
|
+
- fix tests
|
7
|
+
|
8
|
+
## [4.3.0] - 2018-04-17
|
9
|
+
- release 4.3.0.pre as 4.3.0 unchanged
|
10
|
+
|
11
|
+
## [4.3.0.pre] - 2018-04-12
|
12
|
+
- relax railties requirement to not have an upper limit
|
13
|
+
|
4
14
|
## [4.2.0] - 2017-04-28
|
5
15
|
- relax railties requirement to < 5.2
|
6
16
|
|
data/README.md
CHANGED
@@ -16,6 +16,34 @@ It lets you mix and match `//= require` directives and `require()` calls for in
|
|
16
16
|
6. Require modules relative to asset paths (ie app/assets/javascript) with non-relative syntax (see below before using)
|
17
17
|
7. Configure browserify options for each JavaScript file so you can mark modules with `--require`, `--external`, etc
|
18
18
|
|
19
|
+
## Should you use this gem?
|
20
|
+
|
21
|
+
As the primary developer, I'm going to offer some opiniated advice. The sweet spot for this
|
22
|
+
gem is for Rails projects with legacy JavaScript (not using CommonJS/modules). This gem is
|
23
|
+
a great way to make it possible to rewrite that legacy JavaScript to CommonJS on a timeline
|
24
|
+
that you dictate. Then consider stepping off the Rails asset pipeline or using another gem.
|
25
|
+
|
26
|
+
If you're starting a new Rails project today, I highly recommend looking at alternatives to
|
27
|
+
this gem. The primary reason is that this gem, while it works well, is not as efficient as
|
28
|
+
most would like for local development. Also a lot has changed over the last couple of years.
|
29
|
+
|
30
|
+
An example of that change is this project from Rails:
|
31
|
+
|
32
|
+
[rails/webpacker](https://github.com/rails/webpacker)
|
33
|
+
|
34
|
+
This is a huge step in the right direction for the Rails community. In the past, it has been
|
35
|
+
extremely frustrating working with JavaScript on the asset pipeline. The good news is you have a lot
|
36
|
+
of great choices. If I were starting a new Rails project today, I think the safest choice is
|
37
|
+
one in which you have a [Procfile](https://mattstauffer.co/blog/using-a-procfile-to-streamline-your-local-development) that kicks off a separate Webpack build and you use zero
|
38
|
+
Rails magic. A slightly less safe but maybe more convenient choice would be trying rails/webpacker
|
39
|
+
or another gem. The choice is yours.
|
40
|
+
|
41
|
+
|
42
|
+
For more discussion on this topic, see issues
|
43
|
+
[203](https://github.com/browserify-rails/browserify-rails/issues/203),
|
44
|
+
[161](https://github.com/browserify-rails/browserify-rails/issues/161),
|
45
|
+
[43](https://github.com/browserify-rails/browserify-rails/issues/43), etc.
|
46
|
+
|
19
47
|
## Getting Started
|
20
48
|
|
21
49
|
Add this line to your application's Gemfile:
|
@@ -235,13 +263,29 @@ buildpacks that run `bundle` and `npm install` on the target machine.
|
|
235
263
|
|
236
264
|
## Using Browserify Transforms
|
237
265
|
|
238
|
-
You can easily use a browserify transform by
|
266
|
+
You can easily use a browserify transform by making some additions to your `package.json` and creating a .babelrc. For example, here is how you can add ES6 support in your app:
|
239
267
|
|
240
|
-
1. Add `babelify` and `babel-preset-es2015` to your `package.json` in your app's root directory
|
241
|
-
2.
|
242
|
-
|
243
|
-
|
244
|
-
|
268
|
+
1. Add `babelify` and `babel-preset-es2015` to your `package.json` in your app's root directory either by editing the file directly and running `npm install` or using `npm install babelify --save` and `npm install babel-preset-es2015 --save`
|
269
|
+
2. Update your `package.json` to contain the babelify transform by adding the following lines
|
270
|
+
```
|
271
|
+
"browserify": {
|
272
|
+
"transform": [
|
273
|
+
[
|
274
|
+
"babelify"
|
275
|
+
]
|
276
|
+
]
|
277
|
+
}
|
278
|
+
```
|
279
|
+
3. Create a `.babelrc` file in the project root with the following contents
|
280
|
+
```
|
281
|
+
{
|
282
|
+
"plugins": [],
|
283
|
+
"presets": ["es2015"]
|
284
|
+
}
|
285
|
+
```
|
286
|
+
|
287
|
+
4. Create some `.es6` files and require them with `var m = require('./m.es6')` or `import m from './m.es6'`
|
288
|
+
5. Restart your server, and you now have ES6 support!
|
245
289
|
|
246
290
|
|
247
291
|
## Troubleshooting
|
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"
|
22
|
+
spec.add_runtime_dependency "railties", ">= 4.0.0"
|
23
23
|
spec.add_runtime_dependency "sprockets", ">= 3.6.0"
|
24
24
|
spec.add_runtime_dependency "addressable", ">= 2.4.0"
|
25
25
|
|
@@ -41,12 +41,12 @@ module BrowserifyRails
|
|
41
41
|
resolved = input[:environment].resolve(path)
|
42
42
|
|
43
43
|
if resolved && resolved.is_a?(Array)
|
44
|
-
|
45
|
-
elsif
|
46
|
-
|
44
|
+
dependencies += resolved[1]
|
45
|
+
elsif resolved
|
46
|
+
dependencies << "file-digest://#{Addressable::URI.escape resolved}"
|
47
|
+
elsif config.evaluate_node_modules
|
48
|
+
dependencies << "file-digest://#{Addressable::URI.escape path}"
|
47
49
|
end
|
48
|
-
|
49
|
-
dependencies << "file-digest://#{Addressable::URI.escape resolved}" if resolved
|
50
50
|
end
|
51
51
|
|
52
52
|
new_data = run_browserify(input[:name])
|
data/test/compilation_test.rb
CHANGED
@@ -182,6 +182,7 @@ class BrowserifyTest < ActionDispatch::IntegrationTest
|
|
182
182
|
get "/assets/node_path_based_require.js"
|
183
183
|
|
184
184
|
assert_response :success
|
185
|
+
|
185
186
|
assert_equal expected_output, @response.body.strip
|
186
187
|
assert_equal false, @response.body.include?("Error: Cannot find module 'some_folder/answer'")
|
187
188
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|