Rollup is a highly optimized JavaScript module bundler that compiles small pieces of code into larger, more complex libraries or applications. It primarily leverages the standardized ES module format (ESM) for code, enabling advanced optimizations like tree-shaking to produce exceptionally small and efficient bundles. Rollup's current stable version is `4.60.2`, with frequent minor and patch releases (often weekly or bi-weekly) addressing bugs and adding features, while major versions introduce significant changes. Unlike bundlers focused on web applications, Rollup excels at bundling libraries and frameworks, offering a lean core with a powerful, flexible plugin API to handle various build scenarios, including CommonJS, AMD, UMD, and ES module outputs for different environments.
npm install steal-rollupVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically use Rollup with its JavaScript API to bundle a project, including common plugins for module resolution and CommonJS conversion, and outputs to an ES module format with sourcemaps.
Ensure your Node.js environment is 18.0.0 or higher. Update Rollup plugins to their latest compatible versions. Adjust plugin `transform` and `load` hooks to explicitly return `undefined` if they aren't processing a module. Review your `InputOptions` for `moduleSideEffects` if your bundle relies on side effects. Update plugin API usage as per Rollup 4 migration guide, particularly `this.resolve` default `skipSelf: true` for plugin authors.
Refactor custom plugins to avoid returning import attributes from `load` or `transform` hooks. Use `this.addWatchFile()` within plugin `load` hooks for virtual files to ensure they are watched.
Install `@rollup/plugin-commonjs` and `@rollup/plugin-node-resolve` from npm, and add them to your `rollup.config.js` or programmatic input options. For example: `plugins: [resolve(), commonjs()]`.
If your Rollup configuration produces multiple output chunks (e.g., due to multiple inputs or dynamic imports), ensure `output.dir` is used to specify an output directory, rather than `output.file`. For single-file bundles, `output.file` is appropriate.
Set `"moduleResolution": "bundler"` (or `'node16'`, `'nodenext'`) in your `tsconfig.json`'s `compilerOptions`. Alternatively, `"skipLibCheck": true` might resolve certain type issues, but is less precise. Also ensure all source files are included in `tsconfig.json`'s `include` array.
If the module is CommonJS, you might need to use `import * as name from 'module'` or ensure `@rollup/plugin-commonjs` is configured correctly and placed *after* `@rollup/plugin-node-resolve` in your plugin list. If it's an ESM module, verify the named export exists.
Change your Rollup configuration to use `output.dir: 'dist'` (or your desired output directory) instead of `output.file: 'bundle.js'` when your build process generates more than one output chunk.
Rename your configuration file to `rollup.config.mjs` to explicitly tell Node.js to treat it as an ES module, or add `"type": "module"` to your `package.json` file.
Verify that all `.ts` and `.tsx` files intended for bundling are correctly listed in the `include` array within your `tsconfig.json`. Also, ensure that the `@rollup/plugin-typescript` (or equivalent) is properly configured in your Rollup setup.
No dependency data recorded yet.