|
77 | 77 | If you want to customize this with different plugins and presets, specify them
|
78 | 78 | in the `configure_sprockets_bumble_d` block with the `babel_options` setting.
|
79 | 79 | 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. |
83 | 84 |
|
84 | 85 | For example:
|
85 | 86 | ```ruby
|
@@ -191,9 +192,36 @@ application) where the module lives, `register_umd_globals` will raise
|
191 | 192 | registered a second time. Of course, this still can't prevent you from
|
192 | 193 | registering globals (that had not already been registered) in the wrong engine.
|
193 | 194 |
|
194 |
| - |
195 | 195 | ### Reminder about Rails reloading
|
196 | 196 |
|
197 | 197 | As with any `config` changes, updates to the globals registry are not
|
198 | 198 | reloaded automatically; you must restart your server for the changes to take
|
199 | 199 | 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