Skip to content

babel-preset-optimise additions #149

@tunnckoCore

Description

@tunnckoCore

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';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions