Skip to content

Commit 6fd7d38

Browse files
committed
Document ability to transform to other module formats if desired
1 parent 357c36c commit 6fd7d38

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ and
7777
If you want to customize this with different plugins and presets, specify them
7878
in the `configure_sprockets_bumble_d` block with the `babel_options` setting.
7979
Note that (because it's central to the purpose of this gem)
80-
babel-plugin-transform-es2015-modules-umd is _always_ included for you and set
81-
to use the [registered globals](#registering-globals), so this plugin does not
82-
need to be specified when you override the default plugins.
80+
babel-plugin-transform-es2015-modules-umd is _always_ included for you (unless
81+
you [set `transform_to_umd` to `false`](#do-i-have-to-transpile-to-umd-modules))
82+
and configured to use the [registered globals](#registering-globals), so this
83+
plugin does not need to be specified when you override the default plugins.
8384

8485
For example:
8586
```ruby
@@ -191,9 +192,36 @@ application) where the module lives, `register_umd_globals` will raise
191192
registered a second time. Of course, this still can't prevent you from
192193
registering globals (that had not already been registered) in the wrong engine.
193194

194-
195195
### Reminder about Rails reloading
196196

197197
As with any `config` changes, updates to the globals registry are not
198198
reloaded automatically; you must restart your server for the changes to take
199199
effect.
200+
201+
### Do I have to transpile to UMD modules?
202+
203+
No, you can transpile to other module formats (e.g. AMD). You'd just be using
204+
less of this gem's API surface area <sup>1</sup>. You can set `transform_to_umd` to
205+
`false` in your `configure_sprockets_bumble_d` block, and
206+
[override the default plugins](#customizing-your-babel-options) to use a
207+
different module transform. For example if you're using an AMD loader like
208+
[almond](https://github.com/requirejs/almond), you could configure modules to
209+
be transpiled to AMD like so:
210+
211+
```rb
212+
configure_sprockets_bumble_d do |config|
213+
config.root_dir = File.expand_path('..', __dir__)
214+
config.babel_config_version = 1
215+
config.transform_to_umd = false
216+
config.babel_options = {
217+
presets: ['es2015'],
218+
plugins: ['external-helpers', 'transform-es2015-modules-amd']
219+
}
220+
end
221+
```
222+
223+
You can reference the [5.0_amd test app](./test/test_apps/5.0_amd) which
224+
demonstrates this in a full application.
225+
226+
<sup><sup>1</sup> Of course if you're doing this, you wouldn't ever call
227+
`register_umd_globals`</sup>

0 commit comments

Comments
 (0)