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

Maybe should compile node_modules with babel when use inline dependencies #936

Open
EthianWong opened this issue Mar 11, 2022 · 7 comments

Comments

@EthianWong
Copy link

Now microbundle is use exclude: 'node_modules/**' to create babel config, I think it's reasonable when not inline dependencies.
But if use inline dependencies... this options maybe is weird?

// foo/bar.js (in node_modules)
module.exports = {a: ()=>console.log('1')}
// My module
import abc from 'foo/bar.js';
window.de = abc

export const b = () => {
  console.log('2')
}

Then add foo module to devDependencies.

Result:

window.de={a:()=>console.log("1")};var o=function(){console.log('2')};export{o as b};

If i use inline dependencies mean i hope it's part of mine module, my modules arrow function has compile (it's right) but foo modules has nothing change.

Maybe should not set exclude: 'node_modules/**' when use inline dependencies?

@EthianWong
Copy link
Author

We encourage library authors not to distribute code that uses untranspiled ES6 features (other than modules) for this reason. Consumers of your library should not have to transpile your ES6 code, any more than they should have to transpile your CoffeeScript, ClojureScript or TypeScript. ------- @rollup/plugin-babel

The rollup officials not recommend use untranspiled ES6 features to the module, but some authors don't think so, such as debug. So should microbundle allow developers to choose whether to enable babel for node_modules when they use inline dependencies? Currently mcicorbundle specifies exclude: 'node_modules/**' which leaves no way for developers to change.

@EthianWong
Copy link
Author

@developit @rschristian How do you feel about this?

@bradfrosty
Copy link

bradfrosty commented Mar 25, 2022

This makes a lot of sense in my opinion specifically for inlined dependencies. If the inlined dependency is not transpiled, this means the application needs to re-transpile a library built by microbundle. Wouldn't that make using non-modern mode for this library irrelevant, if it contains a mix of transpiled and untranspiled code in the bundle?

@developit
Copy link
Owner

FWIW I am in favor of this. My preference would be to run the "modern to legacy" portion of the JS transpilation on bundles, rather than on source files, similar to the setup described in this diagram:
https://github.com/developit/optimize-plugin#how-does-this-work

@iShawnWang
Copy link

iShawnWang commented Nov 1, 2022

Same issue here, such as query-string release es6 code to npm : https://github.com/sindresorhus/query-string/issues?q=es5

@aries-wlb
Copy link

may I ask what's the solution for this? Meet the same issue and I want to transpile the specific package in node_modules.

@rschristian
Copy link
Collaborator

There's no built-in/automatic solution for the moment, but you can, post-build, run Babel over your bundles to remove any erroneous modern features.

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

6 participants