Skip to content

Commit 409f398

Browse files
author
Matt Wondra
committed
Update README.md
1 parent 2a9daad commit 409f398

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ This is highlighted in [sprockets_require_concat_error.js](https://github.com/ma
1919
//= require "modules/c"
2020
```
2121

22+
*[compiled script](https://github.com/mattwondra/browserify-rails-issue/blob/master/public/assets_compiled/sprockets_require_concat_error.js)*
23+
2224
When the three modules are consecutively required using Sprockets like this, the processed script throws the following runtime error:
2325

2426

@@ -52,6 +54,8 @@ The next example is highlighted in [sprockets_require.js](https://github.com/mat
5254
//= require "modules/c"
5355
```
5456

57+
*[compiled script](https://github.com/mattwondra/browserify-rails-issue/blob/master/public/assets_compiled/sprockets_require.js)*
58+
5559
Note that I've inserted `noop` scripts between the modules as a quick fix for Issue 1 above. However this suffers its own issues. If you look at the processed script, you notice that the shared `lib/counter` library is declared three times: once for each module. So it seems that because Sprockets processes each `//= require`-d file separately, there's no way for them to share common modules.
5660

5761
I know there are [documented ways around this](https://github.com/browserify-rails/browserify-rails#multiple-bundles) but it seems a huge burden to update a YAML config so heavily on a large project with many files and multiple shared dependencies. And while for many modules the worst case is your final file declares the same file many times (probably made negligent with gzip) — for others there are catastrophic results with initializing one library several times on the same page (React in particular).
@@ -67,4 +71,6 @@ var module_b = require("./modules/b");
6771
var module_c = require("./modules/c");
6872
```
6973

74+
*[compiled script](https://github.com/mattwondra/browserify-rails-issue/blob/master/public/assets_compiled/browserify_require.js)*
75+
7076
By including the modules through Browserify, rather than sprockets, you get the desired result. Namely, the shared module `lib/counter` is instantiated exactly once and shared between the other modules.

0 commit comments

Comments
 (0)