lib.bundle

  • Type: boolean
  • Default: true

Specify whether to bundle the library, which is known as bundle mode when bundle is set to true, and bundleless mode when set to false.

See bundle / bundleless for more details.

WARNING

The bundleless mode is not fully supported yet, and some features like assets may not work properly.

Set Entry

We should specify the entry file for the build.

bundle: true

When bundle is set to true, the entry should be set to the entry file. The default entry is src/index.(ts|js|tsx|jsx|mjs|cjs). You should make sure that the entry file exists, or customize entry through the source.entry configuration.

rslib.config.ts
export default {
  lib: [
    {
      format: 'cjs',
      bundle: true,
    },
  ],
  source: {
    entry: {
      index: './foo/index.ts',
    },
  },
};

bundle: false

When bundle is set to false, the entry should be set a glob pattern to include all the files.

rslib.config.ts
export default {
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: './src/**',
    },
  },
};

You can also use with an exclamation mark to exclude some files.

rslib.config.ts
export default {
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: ['./src/**', '!**/foo.*'],
    },
  },
};

Example

For below file structure of source code:

. ├── src │ ├── index.ts │ ├── foo.ts │ └── bar.ts └── package.json

bundle: true

rslib.config.ts
export default defineConfig({
  lib: [
    {
      format: 'cjs',
      bundle: true,
    },
  ],
});

When bundle is set to true, as known as bundle mode, Rslib will bundle the library into a single file.

.
+ ├── dist
+ │   └── index.js
  ├── src
  │   ├── index.ts
  │   ├── foo.ts
  │   └── bar.ts
  └── package.json

bundle: false

rslib.config.ts
export default defineConfig({
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: ['./src/**'],
    },
  },
});

When bundle is set to false, as known as bundleless mode, Rslib will only transform the code into multiple files.

.
+ ├── dist
+ │   ├── index.js
+ │   ├── foo.js
+ │   └── bar.js
  ├── src
  │   ├── index.ts
  │   ├── foo.ts
  │   └── bar.ts
  └── package.json