Conversation
b7404f6
to
93ab662
Compare
93ab662
to
bce6018
Compare
Thanks for the very detailed review ❤️ |
I tried to address all comments, open for a second review. |
I have updated the code to use On a side-node, even Babel's UMD wrapper creates unintended globals, in that case |
This should be already fixed in |
I addressed most of the comments, except the question if we should ignore project-wide configuration. Still undecided. In any case, we should probably add a note about the |
Ok, so the only thing we need to decide is if we should load configs for output plugins, right? I think I would be in favor of not loading them, but I don't feel very strongly about it 🤷♂ |
By now I also agree not loading by default should be preferable. I will change this by tomorrow and make sure I document the configFile option |
I have deactivated default config file loading for |
Last question - should we bump peerDep on rollup? Can we validate if someone tries to use an output plugin with older version of rollup? Or is note in a doc about supported versions sufficient? |
Unless you want to use it as an output plugin, babel.generated is fully backwards compatible, so I guess a note in the docs would be sufficient. |
Could you add such? Other than that - I have no further objections. So we should be able to merge this in this week. cc @loganfsmyth could you maybe take a look as well if everything is OK in your eyes? |
I added a note |
In the following days I'm going to look through PRs and such, need to migrate this plugin to the plugin monorepo. @lukastaegert would you prefer to have this published ASAP or can it wait after I'm done with migration? Note that migration will most likely end up major bumping this package anyway. |
Is there a way to try this out yet? Latest release on NPM does not have this feature, and using the repository directly does not seem to work because there are no files in |
I hope to release this in a couple of days - maybe today. Stay tuned. |
I've just published a new |
It works pretty well for me! |
When will this be released as @current instead of @next? |
Hard to tell - please track rollup/plugins#108. I really hope to review it soon. |
I do not see a connection between releasing a version offering babel() as ouput plugin and moving to a different repository. |
The difference is in time put into releasing it and possible maintenance, user issues, etc. It is currently released as next, so if you care about this feature - just use that next version. |
Resolves #303.
This PR will add the ability to run Babel on generated chunks instead of input files. Also, this updates all dependencies to their latest versions if possible. I also updated documentation which I will copy below and which should explain most of the details.
One possible improvement that I did not get to yet and that may be part of a future PR is that in order to deduplicate helpers in a code-splitting setup, this plugin could move all used helpers to a separate chunk that is then emitted in the
generateBundle
hook. This should probably not be the default behaviour but might be made configurable via an option. Unfortunately I do not see how it could be possible to only move shared helpers to a shared chunk as we would only know which helpers are shared AFTER all chunks are processed.I also updated quite a few of the tests as I found them to be either quite unspecific or of the "always green" kind.
Anyway, this is the main part of the documentation update:
Running Babel on the generated code
By setting
options.transformGenerated: true
, you can configure rollup-plugin-babel to run Babel on the output files instead of the input files. This can be used to perform code transformations on the resulting chunks and is the only way to transform Rollup's auto-generated code. By default, the plugin will be applied to all outputs:If you only want to apply it to specific outputs, you can use it as an output plugin:
The
include
,exclude
andextensions
options are ignored when thetransformGenerated
option is used and will produce warnings, and there are a few more points to note that users should be aware of.Finding .babelrc files
Depending on what options are used, this plugin will start looking for
.babelrc
files starting in the directory of the file indicated byoutput.file
or in the directory indicated byoutput.dir
. If neither of these options is used, e.g. when rendering to stdout or when using the JavaScript API, then.babelrc
files are ignored and options need to be passed in manually.Injected helpers
By default, helpers e.g. when transpiling classes will be inserted at the top of each chunk. In contrast to when applying this plugin on the input files, helpers will not be deduplicated across chunks.
You can however use external helpers by adding the
@babel/external-helpers
plugin, which will look for helpers on a global variable namedbabelHelpers
:Alternatively, you can use imported runtime helpers by adding the
@babel/transform-runtime
plugin. Note that to produce valid code e.g. with@babel/env
, it is very recommended to configure the format of modules for that plugin to match the output format used by Rollup: