embroider-build / ember-auto-import

Zero config import from npm packages
Other
361 stars 110 forks source link

Add option to disable decorator transforms in case we are using a different decorator transform plugin #601

Open vstefanovic97 opened 7 months ago

vstefanovic97 commented 7 months ago

We started using https://github.com/ef4/decorator-transforms to build our v2 Ember addons. But when we actually use this addons in our application I noticed some transpilations were happening that shouldn't be there.

Basically when I build the addon code with rollup I can see the addon code is using a lot of modern features like static blocks, private fields etc., but when I inspect the bundle for the addon generated by the main apps build it seems that all that stuff gets transpiled away (even though our browser targets are all latest browsers that should support such syntax)

After some digging around I noticed that these plugins seem to run always, and they are the root cause of this transpilation.

It would be nice if we had an option to not include any of these if we want, like for ember-cli-babel we have the disableDecoratorTransforms option.

Here is a repo with reproduction (See chunk.143 in dists) https://github.com/vstefanovic97/ember-auto-import-decorator-transpilation-example

I left my-app/dist and my-app/dist-when-i-manually-remove-plugins-from-node-modules-ember-auto-import commited on purpose so you can see the difference w/o having to do a build.

For my-app/dist I just ran production build w/o changing anything, but for my-app/dist-when-i-manually-remove-plugins-from-node-modules-ember-auto-import I ran production build while manually removing those plugins from node_modules/ember-auto-import

ef4 commented 7 months ago

ember-auto-import's standard babel config still needs some decorator support. The app's babel config does not apply to auto-imported dependencies. So I think the option you'd want to add is one that would switch ember-auto-import to use decorator-transforms instead of @babel/plugin-proposal-decorators.

I think it would need to be an option because if we made it the default it would be a breaking change to our supported browsers.