-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Feature Request
Is your feature request related to a problem? Please describe.
The problem I'm having started after #10109 was released.
I want to use preset-env to transform static ES modules, but not dynamic imports. Dynamic imports should be left untouched. My case is that I'm building shared components / packages that should be transformed before distributed. However, in the consuming applications using the shared packages above I want Webpack to use the dynamic imports for code splitting. I guess that I could omit transforming our shared packages and then transform them in the consuming packages, however I would like to be able to support certain browsers / environments "out of the box" in the the shared packages.
Describe the solution you'd like
Make it possible to send in caller options to the CLI (supportsDynamicImport and supportsStaticESM). Currently the caller option is getting overridden by the CLI, see this. Caller name should still always be overriden by the CLI. Can't think of any drawbacks supporting this behavior.
Describe alternatives you've considered
Another solution would be to support excluding plugin-proposal-dynamic-import via the preset-env config. This however seems a little redundant, since we already have supportsDynamicImport.
Teachability, Documentation, Adoption, Migration Strategy
Usage from command line
babel --caller '{supportsDynamicImport: false}'
Usage in code
const parseArgv = require('@babel/cli/lib/babel/options').default;
const dirCommand = require('@babel/cli/lib/babel/dir').default;
const fileCommand = require('@babel/cli/lib/babel/file').default;
const { babelOptions, cliOptions } = parseArgv(process.argv);
babelOptions.caller = { supportsDynamicImport: false }; // This will now be taken into affect
const babelEntry = cliOptions.outDir ? dirCommand : fileCommand;
const babelResult = await babelEntry({ babelOptions, cliOptions });