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.

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 in bundle mode 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.

Example:

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 to a glob pattern to include all the files. The default entry in bundleless mode is src/**.

Example:

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

You can also use with an exclamation mark to exclude some files. For example, exclude test files within the src folder:

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

If declaration files generation is enabled, remember to set exclude field in tsconfig.json to avoid generating TypeScript declaration files for the corresponding files.

For example, exclude test files within the src folder:

// tsconfig.json
{
  "include": ["src"],
  "exclude": ["src/**/*.test.ts"]
}

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 transform the code into multiple files.

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