https://ghub.now.sh/babel-preset-optimise
@babel/plugin-syntax-import-meta (always included, even when not options.typescript enabled)
@babel/plugin-transform-flow-strip-types (if options.typescript disabled)
babel-plugin-transform-replace-expressions (thru options.defines)
babel-plugin-macros, cuz why not
@resugar/codemod-modules-commonjs (part of previously known esnext project), for converting CJS to ESM
- add
options.esmodules - if true, expects CJS input and converts it to ESM;
- force disable if
options.rollup which will mean that you use Rollup + Commonjs plugin + Rollup Babel plugin, in which case Rollup's Commonjs plugin deals with CJS input okay
- (always) opposite of
options.commonjs
babel-plugin-add-import-extension adds/replaces extensions
automatically adds /index.${extension} if it's a dir
- import foo from './lib';
+ import foo from './lib/index.js';
a bug:
- import foo from './';
+ import foo from './/index.js';
but this works
- import foo from '.';
+ import foo from './index.js';
or
- import foo from './bar';
+ import foo from './bar.js';
or with replace: true option
- import foo from './src/index.ts';
+ import foo from './src/index.js';
there's also an extension option to the plugin, which is cool too.
Like, forcing some ext with extension: 'ts'
- import foo from './bar';
+ import foo from './bar.ts';
and with both options { extension: 'ts', replace: true }
- import foo from './bar.js';
+ import foo from './bar.ts';
https://ghub.now.sh/babel-preset-optimise
@babel/plugin-syntax-import-meta(always included, even when notoptions.typescriptenabled)@babel/plugin-transform-flow-strip-types(ifoptions.typescriptdisabled)babel-plugin-transform-replace-expressions(thruoptions.defines)babel-plugin-macros, cuz why not@resugar/codemod-modules-commonjs(part of previously knownesnextproject), for converting CJS to ESMoptions.esmodules- if true, expects CJS input and converts it to ESM;options.rollupwhich will mean that you use Rollup + Commonjs plugin + Rollup Babel plugin, in which case Rollup's Commonjs plugin deals with CJS input okayoptions.commonjsbabel-plugin-add-import-extensionadds/replaces extensions.jsextensions inside TS soruce code to reference.tsfiles, sorry what?! 😱 no thanksautomatically adds
/index.${extension}if it's a dira bug:
but this works
or
or with
replace: trueoptionthere's also an
extensionoption to the plugin, which is cool too.Like, forcing some ext with
extension: 'ts'and with both options
{ extension: 'ts', replace: true }