lib.autoExtension

  • Type: boolean
  • Default: true

Whether to automatically set the file extension based on the format option in the JavaScript output files.

Default Extension

By default that when autoExtension is set to true, the file extension will be:

  • .js with esm format and .cjs with cjs format when type: module in package.json.

  • .js with cjs format and .mjs with esm format when type: commonjs or no type field in package.json.

WARNING

When bundle is set to false that as known as bundleless mode, you should write full path instead of ignoring directory indexes (e.g. using './foo' as a shorthand for './foo/index.js') in source code.

For example, if foo is a folder, you need to rewrite import * from './foo' to import * from './foo/index'.

When autoExtension is set to false, the file extension will be default to .js.

Customize Extension

You can set autoExtension to false and use output.filename to customize the JavaScript output files.

rslib.config.ts
export default defineConfig({
  lib: [
    {
      format: 'cjs',
      autoExtension: false,
      output: {
        filename: {
          js: '[name].cjs',
        },
      },
    },
    {
      format: 'esm',
      output: {
        filename: {
          js: '[name].mjs',
        },
      },
    },
  ],
});