@rollup/plugins
repository·master·Indexed 25 days ago
https://github.com/rollup/pluginsA monorepo containing official Rollup plugins that are critical, maintained by the Rollup organization, or recommended for use. Includes plugins such as @rollup/plugin-alias for mapping import paths, @rollup/plugin-auto-install for automatic dependency management, @rollup/plugin-babel for Babel transpilation, and @rollup/plugin-beep.
What's inside @rollup/plugins
- This repository is the central collection of official Rollup plugins. It contains plugins that are considered critical for everyday Rollup usage, those maintained by the Rollup organization, and those officially recommended to users.
Use @rollup/plugin-multi-entry to combine multiple entry points
masterThe
@rollup/plugin-multi-entryplugin allows you to use multiple entry points for a single bundle and combines their named exports into the final bundle.Note:
defaultexports cannot be combined or exported by this plugin; only named exports are supported.Requirements:
- Node.js LTS (v14.0.0+)
- Rollup v1.20.0+
import multi from '@rollup/plugin-multi-entry'; export default { input: ['batman.js', 'robin.js', 'joker.js'], output: { dir: 'output' }, plugins: [multi()] };Install @rollup/plugin-graphql
masterInstall the plugin as a development dependency using npm:
npm install @rollup/plugin-graphql --save-devInstall @rollup/plugin-yaml
masterInstall the
@rollup/plugin-yamlpackage as a development dependency using npm.npm install @rollup/plugin-yaml --save-devHandle symlinks with @rollup/plugin-commonjs
masterIn monorepos or when using
npm link, Rollup (via@rollup/plugin-node-resolve) resolves modules to their real paths by default.When configuring
includeorexcludepaths, you must use the real paths rather than the symlinked paths. To avoid path issues, you can use a regular expression for theincludeoption that matches the module name regardless of the base path.commonjs({ include: /node_modules/ });Reference external CSS/JS files in @rollup/plugin-html
masterYou can use the
templateExternalFilesrecipe from@rollup/plugin-html/recipes/external-filesto inject external CSS and JS files into your generated HTML. This allows you to control the loading sequence of these files relative to the main bundle using theposoption.Each configuration object in the array passed to
templateExternalFilesrequires:type: Either'js'or'css'.file: The path to the external file.pos(optional): Use'before'to place the file before the main bundle, or omit it to place it after the main bundle.
import html from '@rollup/plugin-html'; import templateExternalFiles from '@rollup/plugin-html/recipes/external-files'; export default [ { input: ['demo/demo.ts'], output: [{ file: 'dist/demo.js' }], plugins: [ html({ title: 'sdk demo page', publicPath: './', fileName: 'demo.html', template: templateExternalFiles([ { type: 'js', file: 'example1.js', pos: 'before' }, { type: 'js', file: 'example2.js' }, // Placed after main bundle { type: 'css', file: 'example1.css', pos: 'before' } ]) }) ] } ];Install @rollup/plugin-node-resolve
masterInstall the plugin using npm to enable Node resolution algorithm support for third-party modules in
node_modules.Requirements:
- Node.js LTS (v14.0.0+)
- Rollup v2.78.0+
npm install @rollup/plugin-node-resolve --save-devResolve built-ins using stubs
masterBy default, the plugin prefers Node.js built-ins (like
fs) and marks them as external. To use polyfills instead, setpreferBuiltinstofalseand use a polyfill plugin.import { nodeResolve } from '@rollup/plugin-node-resolve'; import nodePolyfills from 'rollup-plugin-node-polyfills'; export default { input: ..., plugins: [ nodePolyfills(), nodeResolve({ preferBuiltins: false }) ], external: builtins, output: ... }Install @rollup/plugin-beep
masterInstall the
@rollup/plugin-beepplugin as a development dependency using npm.npm install @rollup/plugin-beep --save-devRequirements for @rollup/plugin-auto-install
masterTo use this plugin, ensure your environment meets the following requirements:
- Node.js: LTS version (v14.0.0+)
- Rollup: v1.20.0+
Use @rollup/plugin-dsv in Rollup
masterImport the plugin in your
rollup.config.jsand add it to thepluginsarray. This allows you to import.csvand.tsvfiles directly into your JavaScript modules as arrays of objects.import dsv from '@rollup/plugin-dsv'; export default { input: 'src/index.js', output: { dir: 'output', format: 'cjs' }, plugins: [dsv()] };Install @rollup/plugin-esm-shim
masterInstall the
@rollup/plugin-esm-shimplugin as a development dependency using npm.npm install @rollup/plugin-esm-shim --save-dev