Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel configs are ignored #27

Open
rschristian opened this issue Mar 5, 2022 · 8 comments
Open

Babel configs are ignored #27

rschristian opened this issue Mar 5, 2022 · 8 comments

Comments

@rschristian
Copy link
Contributor

In the ReadMe, there's the following line:

In order to migrate to optimize-plugin, you'll need to move your babel configuration into a .babelrc or babel.config.js file ...optimize-plugin only uses your babel configuration when generating modern bundles.

However, both configFile and babelrc are set to false:

const modern = await babel.transformAsync(source, {
configFile: false,
babelrc: false,

This should stop any config files from being loaded, AFAIK. Am I misunderstanding something, or are the docs outdated perhaps?

@dineshtrivedi
Copy link

I am having the same experience, my .babelrc is being ignored.
Have you found a solution for it @rschristian ?

@rschristian
Copy link
Contributor Author

No solution beyond running Babel separately and before this plugin, no.

I think that's fine and correct for my use case though, so it's not a problem.

@dineshtrivedi
Copy link

Thank you for your response @rschristian
I understand what you mean. Would be possible to share your webpack.config with me, please? It would be extremely helpful to understand how you solved this.

@rschristian
Copy link
Contributor Author

Sorry, this isn't a simple use case.

I have added this for preact-cli, which is a Webpack-based build tool. It's got a fair bit going on in it, but the gist of it is that we use the following Babel config in both dev & prod: https://github.com/preactjs/preact-cli/blob/af9ebd0a9347cbcc36c234981ee9ed212df49990/packages/cli/lib/lib/babel-config.js

@babel/preset-env is only ran in dev, as optimize-plugin here picks that up for prod.

@dineshtrivedi
Copy link

Amazing, @rschristian
Thank you. I have done something similar to you, but you gave me other ideas. I will spend more time on it someday in the coming month.

Thank you again, I really appreciate it.

@rschristian
Copy link
Contributor Author

No problem.

Preact-CLI always have a need for babel-loader, as a) we need something to handle the dev environment and b) we need to handle JSX, TS, decorators, and any other non-standard syntax. That setup "works" for us, though it might not be optimal or how this tool was intended to be used. Not really sure at the moment!

@developit An extra question: given the prevalence of syntax like JSX, TS, decorators, etc., should optimize-plugin's docs be recommending removing babel-loader? As far as I can tell, most users using Webpack are using some non-standard syntax, so the instruction to remove the loader doesn't really make sense to me. Even if passing a babel config to optimze worked, Webpack is going to error out far earlier if there's JSX, TS, or any number of other non-standard syntax.

I just don't see that instruction actually being valid for most users, unless I'm missing something?

@developit
Copy link
Owner

@rschristian I think they could be clearer about this, yes. The docs should say "using a simpler or faster loader to handle non-JS syntax, like Sucrase". The idea isn't necessarily to avoid the need for a loader at all, it's that the loader shouldn't be doing any ES version-related trabspilation.

@rschristian
Copy link
Contributor Author

Gotcha, good to confirm; I didn't imagine the intent was to run this first to handle those transforms (assuming the babel config was customizable) but the docs pointed that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants