### Configure Rollup with @rollup/plugin-strip Source: https://github.com/rollup/plugins/blob/master/packages/strip/README.md Demonstrates how to import and use the @rollup/plugin-strip plugin within a Rollup configuration file (`rollup.config.js`). It shows basic setup with input/output formats and an example of configuring the `labels` option. ```javascript import strip from '@rollup/plugin-strip'; export default { input: 'src/index.js', output: { dir: 'output', format: 'cjs' }, plugins: [ strip({ labels: ['unittest'] }) ] }; ``` -------------------------------- ### Install @rollup/plugin-sucrase Source: https://github.com/rollup/plugins/blob/master/packages/sucrase/README.md Installs the @rollup/plugin-sucrase package as a development dependency using npm. ```bash npm install @rollup/plugin-sucrase --save-dev ``` -------------------------------- ### Install @rollup/plugin-multi-entry Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md Installs the @rollup/plugin-multi-entry package as a development dependency using npm. ```bash npm install @rollup/plugin-multi-entry --save-dev ``` -------------------------------- ### Install @rollup/plugin-alias Source: https://github.com/rollup/plugins/blob/master/packages/alias/README.md Provides instructions for installing the alias plugin using npm or yarn. ```console npm install @rollup/plugin-alias --save-dev # or yarn add -D @rollup/plugin-alias ``` -------------------------------- ### Example Entry File: robin.js Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md An example JavaScript file demonstrating a named export. This file can be used as an entry point with the @rollup/plugin-multi-entry plugin. ```javascript // robin.js export const tights = 'tight'; ``` -------------------------------- ### Install @rollup/plugin-run Source: https://github.com/rollup/plugins/blob/master/packages/run/README.md Installs the @rollup/plugin-run package as a development dependency using npm. ```bash npm install @rollup/plugin-run --save-dev ``` -------------------------------- ### Install @rollup/plugin-replace Source: https://github.com/rollup/plugins/blob/master/packages/replace/README.md Installs the @rollup/plugin-replace package as a development dependency using npm. ```console npm install @rollup/plugin-replace --save-dev ``` -------------------------------- ### Example Entry File: batman.js Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md An example JavaScript file demonstrating a named export. This file can be used as an entry point with the @rollup/plugin-multi-entry plugin. ```javascript // batman.js export const belt = 'utility'; ``` -------------------------------- ### Example Entry File: joker.js Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md An example JavaScript file demonstrating a named export. This file can be used as an entry point with the @rollup/plugin-multi-entry plugin. ```javascript // joker.js export const color = 'purple'; ``` -------------------------------- ### Install @rollup/plugin-graphql Source: https://github.com/rollup/plugins/blob/master/packages/graphql/README.md Installs the @rollup/plugin-graphql package as a development dependency using npm. ```bash npm install @rollup/plugin-graphql --save-dev ``` -------------------------------- ### Example Import Before Alias Source: https://github.com/rollup/plugins/blob/master/packages/alias/README.md Demonstrates a typical import statement that can be simplified using the alias plugin. ```javascript import batman from '../../../batman'; ``` -------------------------------- ### Install @rollup/pluginutils Source: https://github.com/rollup/plugins/blob/master/packages/pluginutils/README.md Installs the @rollup/pluginutils package as a development dependency using npm. ```console npm install @rollup/pluginutils --save-dev ``` -------------------------------- ### Install pnpm Source: https://github.com/rollup/plugins/blob/master/README.md Installs the pnpm package manager globally, which is used for dependency management in the Rollup monorepo. ```console $ npm install pnpm -g ``` -------------------------------- ### Install @rollup/plugin-html Source: https://github.com/rollup/plugins/blob/master/packages/html/README.md Installs the @rollup/plugin-html package as a development dependency using npm. ```console npm install @rollup/plugin-html --save-dev ``` -------------------------------- ### Install @rollup/plugin-image Source: https://github.com/rollup/plugins/blob/master/packages/image/README.md Installs the @rollup/plugin-image package as a development dependency using npm. ```console npm install @rollup/plugin-image --save-dev ``` -------------------------------- ### Install @rollup/plugin-dynamic-import-vars Source: https://github.com/rollup/plugins/blob/master/packages/dynamic-import-vars/README.md Provides the npm command to install the plugin as a development dependency. ```bash npm install @rollup/plugin-dynamic-import-vars --save-dev ``` -------------------------------- ### Install @rollup/plugin-beep Source: https://github.com/rollup/plugins/blob/master/packages/beep/README.md Installs the @rollup/plugin-beep package as a development dependency using npm. ```bash npm install @rollup/plugin-beep --save-dev ``` -------------------------------- ### Install @rollup/plugin-strip Source: https://github.com/rollup/plugins/blob/master/packages/strip/README.md Installs the @rollup/plugin-strip package as a development dependency using npm. ```console npm install @rollup/plugin-strip --save-dev ``` -------------------------------- ### Install @rollup/plugin-auto-install Source: https://github.com/rollup/plugins/blob/master/packages/auto-install/README.md This command installs the @rollup/plugin-auto-install package as a development dependency using npm. ```bash npm install @rollup/plugin-auto-install --save-dev ``` -------------------------------- ### Install @rollup/plugin-url Source: https://github.com/rollup/plugins/blob/master/packages/url/README.md Installs the @rollup/plugin-url package as a development dependency using npm. ```bash npm install @rollup/plugin-url --save-dev ``` -------------------------------- ### Install @rollup/plugin-json Source: https://github.com/rollup/plugins/blob/master/packages/json/README.md Installs the @rollup/plugin-json package as a development dependency using npm. ```bash npm install @rollup/plugin-json --save-dev ``` -------------------------------- ### Configure Rollup with WASM Plugin Source: https://github.com/rollup/plugins/blob/master/packages/wasm/README.md Example Rollup configuration file (rollup.config.js) demonstrating how to import and use the wasm plugin. ```javascript import { wasm } from '@rollup/plugin-wasm'; export default { input: 'src/index.js', output: { dir: 'output', format: 'cjs' }, plugins: [wasm()] }; ``` -------------------------------- ### Install @rollup/plugin-swc Source: https://github.com/rollup/plugins/blob/master/packages/swc/README.md Installs the @rollup/plugin-swc and its core dependency @swc/core as development dependencies using npm. ```console npm install @swc/core @rollup/plugin-swc --save-dev ``` -------------------------------- ### Plugin IsEntry Example Source: https://github.com/rollup/plugins/blob/master/packages/commonjs/test/snapshots/function.js.md This example demonstrates the 'plugin-isentry' functionality, which detects entry points in a Rollup build. It includes a main JavaScript file that sets a global flag and a dependency file that checks this flag. ```javascript 'use strict'; global.entryDetected = true; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var dep; var hasRequiredDep; function requireDep () { if (hasRequiredDep) return dep; hasRequiredDep = 1; t.is(commonjsGlobal.entryDetected, true); dep = 'dep'; return dep; } var main$1; var hasRequiredMain; function requireMain () { if (hasRequiredMain) return main$1; hasRequiredMain = 1; t.is(commonjsGlobal.entryDetected, true); main$1 = requireDep(); return main$1; } var mainExports = requireMain(); var main = /*@__PURE__*/getDefaultExportFromCjs(mainExports); module.exports = main; ``` ```javascript 'use strict'; const other = true; exports.other = other; ``` -------------------------------- ### Install @rollup/plugin-data-uri Source: https://github.com/rollup/plugins/blob/master/packages/data-uri/README.md Installs the @rollup/plugin-data-uri package as a development dependency using npm. ```bash npm install @rollup/plugin-data-uri --save-dev ``` -------------------------------- ### JavaScript - Rollup Plugin Example Source: https://github.com/rollup/plugins/blob/master/packages/image/test/snapshots/test.js.md A basic example demonstrating the structure of a Rollup plugin in JavaScript. Plugins are essential for extending Rollup's functionality, allowing for custom transformations and optimizations during the bundling process. ```JavaScript export default function myRollupPlugin() { return { name: 'my-rollup-plugin', // Example hook: transform transform(code, id) { console.log(`Transforming file: ${id}`); // Return transformed code or null if no transformation is needed return { code: code.replace('import', '// imported'), map: null // Provide source map if available }; }, // Example hook: generateBundle generateBundle(options, bundle) { console.log('Generating bundle...'); // Modify or add files to the bundle this.emitFile({ type: 'asset', fileName: 'my-asset.txt', source: 'This is a custom asset.' }); } }; } ``` -------------------------------- ### Example Import After Alias Source: https://github.com/rollup/plugins/blob/master/packages/alias/README.md Shows the same import statement after applying an alias, highlighting improved readability and maintainability. ```javascript import batman from 'batman'; ``` -------------------------------- ### Basic Rollup Configuration with @rollup/plugin-html Source: https://github.com/rollup/plugins/blob/master/packages/html/README.md Demonstrates a basic `rollup.config.js` setup to use the @rollup/plugin-html. It imports the plugin and includes it in the `plugins` array. ```javascript const html = require('@rollup/plugin-html'); module.exports = { input: 'src/index.js', output: { dir: 'output', format: 'cjs' }, plugins: [html()] }; ``` -------------------------------- ### HTML - Rollup Plugin Usage Example Source: https://github.com/rollup/plugins/blob/master/packages/image/test/snapshots/test.js.md Demonstrates how to integrate a Rollup plugin within a Rollup configuration file (rollup.config.js), which is typically written in JavaScript but often referenced in HTML documentation or setup guides. ```JavaScript import myRollupPlugin from './myRollupPlugin.js'; export default { input: 'src/main.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [ myRollupPlugin(), // Other plugins like @rollup/plugin-node-resolve, @rollup/plugin-commonjs, etc. ] }; ``` -------------------------------- ### Install @rollup/plugin-commonjs Source: https://github.com/rollup/plugins/blob/master/packages/commonjs/README.md Installs the @rollup/plugin-commonjs package as a development dependency using npm. ```bash npm install @rollup/plugin-commonjs --save-dev ``` -------------------------------- ### Basic Rollup Configuration with @rollup/plugin-run Source: https://github.com/rollup/plugins/blob/master/packages/run/README.md Demonstrates how to configure Rollup to use the @rollup/plugin-run plugin. It specifies the input and output files and formats, and includes the plugin in the `plugins` array. ```javascript import run from '@rollup/plugin-run'; export default { input: 'src/index.js', output: { file: 'dist/index.js', format: 'cjs' }, plugins: [run()] }; ``` -------------------------------- ### Install @rollup/plugin-node-resolve Source: https://github.com/rollup/plugins/blob/master/packages/node-resolve/README.md Installs the @rollup/plugin-node-resolve package as a development dependency using npm. ```bash npm install @rollup/plugin-node-resolve --save-dev ``` -------------------------------- ### GraphQL Fragment Import Example Source: https://github.com/rollup/plugins/blob/master/packages/graphql/README.md Illustrates how to import and use GraphQL fragments within .graphql files, leveraging the graphql-tag library's import syntax. ```graphql #import "./heroFragment.graphql" query AllHeroes { heros { ...HeroFragment } } ``` -------------------------------- ### Node.js Exports Pattern Example Source: https://github.com/rollup/plugins/blob/master/packages/node-resolve/README.md Presents the recommended Node.js package.json exports mapping using patterns, which replaces the deprecated folder mapping. This is the modern approach for defining package entry points. ```json { "exports": { "./foo/*": "./dist/foo/*" } } ``` -------------------------------- ### Install @rollup/plugin-esm-shim Source: https://github.com/rollup/plugins/blob/master/packages/esm-shim/README.md Installs the @rollup/plugin-esm-shim package as a development dependency using npm. ```bash npm install @rollup/plugin-esm-shim --save-dev ``` -------------------------------- ### Rollup Configuration with Auto-Install Source: https://github.com/rollup/plugins/blob/master/packages/auto-install/README.md This JavaScript code demonstrates how to configure Rollup to use the @rollup/plugin-auto-install along with @rollup/plugin-node-resolve. It specifies the input and output formats and the order of plugin execution. ```javascript import auto from '@rollup/plugin-auto-install'; import resolve from '@rollup/plugin-node-resolve'; export default { input: 'src/index.js', output: { dir: 'output', format: 'cjs' }, plugins: [auto(), resolve()] }; ``` -------------------------------- ### Debugging with Source Maps using @rollup/plugin-run Source: https://github.com/rollup/plugins/blob/master/packages/run/README.md Configures the @rollup/plugin-run plugin to enable debugging with source maps by passing `execArgv` options to the child process. This example integrates with the `source-map-support` package. ```javascript // rollup.config.js import run from '@rollup/plugin-run'; export default { input: 'src/index.js', output: { file: 'dist/index.js', format: 'cjs', sourcemap: true }, plugins: [ run({ execArgv: ['-r', 'source-map-support/register'] }) ] }; ``` -------------------------------- ### TypeScript Plugin Error: tslib Not Installed Source: https://github.com/rollup/plugins/blob/master/packages/typescript/test/snapshots/tslib.ts.md This snippet illustrates a failure where the Rollup TypeScript plugin cannot execute because the 'tslib' module is not installed in the project. The error message explicitly states that 'tslib' is required and suggests checking its installation. ```javascript RollupError (Error) { code: 'PLUGIN_ERROR', hook: 'buildStart', plugin: 'typescript', message: '@rollup/plugin-typescript: Could not find module 'tslib', which is required by this plugin. Is it installed?' } ``` -------------------------------- ### Babel ES Module Output Example Source: https://github.com/rollup/plugins/blob/master/packages/babel/README.md Illustrates the input and output code when using Babel for ES module transpilation, showing the import of @babel/runtime helpers. ```javascript // input export default class Foo {} // output import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck'; var Foo = function Foo() { _classCallCheck(this, Foo); }; export default Foo; ``` -------------------------------- ### Install @rollup/plugin-wasm Source: https://github.com/rollup/plugins/blob/master/packages/wasm/README.md Command to install the @rollup/plugin-wasm package as a development dependency using npm. ```bash npm install @rollup/plugin-wasm --save-dev ``` -------------------------------- ### Install @rollup/plugin-virtual Source: https://github.com/rollup/plugins/blob/master/packages/virtual/README.md Installs the @rollup/plugin-virtual package as a development dependency using npm. ```console npm install @rollup/plugin-virtual --save-dev ``` -------------------------------- ### Handle Multiple Entry Points (JavaScript) Source: https://github.com/rollup/plugins/blob/master/packages/commonjs/test/snapshots/function.js.md Explains the strict-requires-multiple-entry plugin's approach to managing dependencies across multiple entry points in a project. It includes examples for a generated file, the main entry point, and an 'other' file. ```javascript 'use strict'; var main = {}; var hasRequiredMain; function requireMain () { if (hasRequiredMain) return main; hasRequiredMain = 1; main.foo = 'foo'; return main; } exports.requireMain = requireMain; ``` ```javascript 'use strict'; var main$1 = require('./generated-main.js'); function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var mainExports = main$1.requireMain(); var main = /*@__PURE__*/getDefaultExportFromCjs(mainExports); module.exports = main; ``` ```javascript 'use strict'; var main = require('./generated-main.js'); var other = {}; t.is(main.requireMain().foo, 'foo'); module.exports = other; ``` -------------------------------- ### Basic Rollup Configuration with Multi-Entry Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md Demonstrates a basic Rollup configuration using the multi-entry plugin. It specifies multiple JavaScript files as entry points and configures the output directory. The named exports from 'batman.js', 'robin.js', and 'joker.js' will be combined into the bundle. ```javascript import multi from '@rollup/plugin-multi-entry'; export default { input: ['batman.js', 'robin.js', 'joker.js'], output: { dir: 'output' }, plugins: [multi()] }; ``` -------------------------------- ### Install @rollup/plugin-inject Source: https://github.com/rollup/plugins/blob/master/packages/inject/README.md Installs the @rollup/plugin-inject package as a development dependency using npm. ```console npm install @rollup/plugin-inject --save-dev ``` -------------------------------- ### Using CommonJS as Entry Point with ES Module Re-export Source: https://github.com/rollup/plugins/blob/master/packages/commonjs/README.md Demonstrates how to use a CommonJS file as an entry point for Rollup, re-exporting its named exports from an ES module. This ensures named exports are available when bundling to an ES module format. ```cjs // main.cjs, the CommonJS entry exports.foo = 'foo'; exports.bar = 'bar'; ``` ```mjs // main.mjs, the ES module entry export { foo, bar } from './main.cjs'; ``` ```mjs // rollup.config.mjs export default { input: 'main.mjs', output: { format: 'es', file: 'bundle.mjs' } }; ``` -------------------------------- ### Template Handling with Rollup Source: https://github.com/rollup/plugins/blob/master/packages/html/test/snapshots/test.js.md This snippet shows a basic Rollup setup for handling HTML templates. It includes a JavaScript file and a simple HTML file that likely serves as the template or entry point. ```javascript (function (factory) { typedefine === 'function' && define.amd ? define(factory) : factory(); })(function () { 'use strict'; }); ``` ```html
``` -------------------------------- ### JavaScript Module Initialization and Testing Source: https://github.com/rollup/plugins/blob/master/packages/commonjs/test/snapshots/function.js.md Illustrates a common pattern for initializing modules and testing their functionality in JavaScript. This snippet shows how to manage dependencies and assert values using a testing framework. ```javascript 'use strict'; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var main$1 = {}; var foo; var hasRequiredFoo; function requireFoo () { if (hasRequiredFoo) return foo; hasRequiredFoo = 1; foo = 42; return foo; } var hasRequiredMain; function requireMain () { if (hasRequiredMain) return main$1; hasRequiredMain = 1; const foo = requireFoo(); t.is(foo, 42); return main$1; } var mainExports = requireMain(); var main = /*@__PURE__*/getDefaultExportFromCjs(mainExports); module.exports = main; ``` -------------------------------- ### Install @rollup/plugin-babel Source: https://github.com/rollup/plugins/blob/master/packages/babel/README.md This command installs the @rollup/plugin-babel package as a development dependency using npm. ```bash npm install @rollup/plugin-babel --save-dev ``` -------------------------------- ### Rollup Configuration with Array Input Source: https://github.com/rollup/plugins/blob/master/packages/multi-entry/README.md Illustrates using an array of strings for the input option in Rollup. This allows specifying multiple files and/or glob patterns as entry points. ```javascript export default { input: ['party/supplies.js', 'batcave/friends/**/*.js'], plugins: [multi()] // ... }; ``` -------------------------------- ### Install @rollup/plugin-eslint Source: https://github.com/rollup/plugins/blob/master/packages/eslint/README.md Installs the @rollup/plugin-eslint package as a development dependency using either npm or yarn. ```console npm install @rollup/plugin-eslint --save-dev yarn add -D @rollup/plugin-eslint ``` -------------------------------- ### Install @rollup/plugin-dsv Source: https://github.com/rollup/plugins/blob/master/packages/dsv/README.md Installs the @rollup/plugin-dsv package as a development dependency using npm. ```console npm install @rollup/plugin-dsv --save-dev ```