[TIMOB-24980] Allow babel plugins to be added via config.json
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | High |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | Alloy 2.0.0 |
Components | Tooling |
Labels | alloy, babel |
Reporter | Brenton House |
Assignee | Christopher Williams |
Created | 2017-07-18T18:46:28.000+0000 |
Updated | 2019-03-14T14:24:19.000+0000 |
Description
{noformat}
As a developer,
I want to be able to add/configure babel plugins to run on my code,
So that I can add features without Alloy pull request.
{noformat}
There are a lot of features that can be added to Alloy by allow babel presets and plugins to be defined in config.json. Currently, it is somewhat possible to add a preset by pushing them to
sourceMapper.OPTIONS_OUTPUT.presets
from inside alloy.jmk. However, when adding plugins, they are removed because Alloy is overwriting all plugins here: https://github.com/appcelerator/alloy/blob/master/Alloy/commands/compile/index.js#L1131-L1136
If instead it used _.defaults
(or even better, a merge), it could preserve any changes to sourceMapper.OPTIONS_OUTPUT.plugins
Thanks for the ticket. Our engineers will look into it.
This is a pretty good idea. I'd also like to be able to give users a way to control additional babel plugins/presets they may want to use in the normal Titanium build process. Right now we do parsing to analyze the JS for Api usage for tracking, and will use babili to minify if minification is turned on. I wonder if users could simply add a .babelrc to their project and we could consume/extend it to also use babili when minifying (and make sure the transpilation happens after we parse to look for Ti API usage for tracking).
There's a work in progress PR here: https://github.com/appcelerator/alloy/pull/842 It has broader implications since alloy is still using underscore and older backbone versions - and underscore doesn't have a deep merge method. Lodash, underscore's more popular fork, does though. And it may make more sense to move to loads, deprecate underscore, and update backbone to latest and have it use lodash under the covers.
[~cwilliams] -- I replace underscore with lodash in most of my alloy projects and am aware of most of the gotchas if you want any help with that. Some of the biggest issues are a result of the fact that the alloy compiler and the alloy runtime share the same underscore.js file. If we could separate that for now, it would make upgrading alloy runtime to lodash much easier. Update -- looks like you have already done this in the PR. I will take a look at it. Thanks!!
OK, so using Lodash in place of underscore is a bigger fish to fry and may be a breaking change (or require allowing users to configure whether they use underscore or loads and deprecating underscore). So I opened a smaller PR just for this change: https://github.com/appcelerator/alloy/pull/843
[~cwilliams] - Is this now something that is supported via the webpack/babel integration?