### Install Plugin Serve Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Install the plugin using npm. ```bash npm install --save-dev @rollup-extras/plugin-serve ``` -------------------------------- ### Install @rollup-extras/plugin-script-loader Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/README.md Install the plugin using npm. ```bash npm install --save-dev @rollup-extras/plugin-script-loader ``` -------------------------------- ### Install Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-angularjs-template-cache/README.md Install the plugin using npm for development. ```bash npm install --save-dev @rollup-extras/plugin-angularjs-template-cache ``` -------------------------------- ### Install @rollup-extras/plugin-strip-comments Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-strip-comments/README.md Install the plugin using npm or pnpm. ```bash npm install --save-dev @rollup-extras/plugin-strip-comments ``` ```bash pnpm add -D @rollup-extras/plugin-strip-comments ``` -------------------------------- ### Install Plugin Binify Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-binify/README.md Install the plugin using npm. ```bash npm install --save-dev @rollup-extras/plugin-binify ``` -------------------------------- ### Install @rollup-extras/plugin-prebundle Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-prebundle/README.md Install the plugin as a development dependency. ```bash npm install --save-dev @rollup-extras/plugin-prebundle ``` -------------------------------- ### Install Rollup Extras Utils Source: https://github.com/kshutkin/rollup-extras/blob/main/utils/README.md Install the utility package as a development dependency. ```bash npm install --save-dev @rollup-extras/utils ``` -------------------------------- ### Full Plugin Options Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-size/README.md Example demonstrating all available options for the plugin. ```javascript size({ statsFile: ".stats.json", updateStats: true, gzip: true, brotli: true, pluginName: "my-size", outputPlugin: false, minify: async (fileName, code) => { // your minification logic return minifiedCode; }, }); ``` -------------------------------- ### Install @rollup-extras/plugin-size Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-size/README.md Install the plugin using npm or pnpm. ```bash npm install --save-dev @rollup-extras/plugin-size ``` ```bash pnpm add -D @rollup-extras/plugin-size ``` -------------------------------- ### Install Rollup Plugin Clean Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-clean/README.md Install the plugin using npm. ```bash npm install --save-dev @rollup-extras/plugin-clean ``` -------------------------------- ### Install Plugin Copy Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-copy/README.md Install the plugin using npm. This is a prerequisite for using it in your Rollup configuration. ```bash npm install --save-dev @rollup-extras/plugin-copy ``` -------------------------------- ### Basic Rollup Configuration with Plugin Externals Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-externals/README.md Configure your Rollup build to use the plugin. This example shows a common setup for a CommonJS output format. ```javascript import externals from '@rollup-extras/plugin-externals'; export default { input: 'src/index.js', output: { format: 'cjs', dir: 'dest' }, plugins: [externals()], } ``` -------------------------------- ### Install Rollup Plugin Exec Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-exec/README.md Install the plugin using npm. This command adds the plugin as a development dependency to your project. ```bash npm install --save-dev @rollup-extras/plugin-exec ``` -------------------------------- ### Install @rollup-extras/plugin-mangle with pnpm Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-mangle/README.md Use this command to install the plugin as a development dependency using pnpm. ```bash pnpm add -D @rollup-extras/plugin-mangle ``` -------------------------------- ### Configure Zero-Config @rollup-extras/plugin-serve Source: https://context7.com/kshutkin/rollup-extras/llms.txt A Hono-based development server that serves Rollup output after each build. This zero-config example serves output.dir on http://localhost:8080. ```javascript import serve from '@rollup-extras/plugin-serve'; // Zero-config: serves output.dir on http://localhost:8080 export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [serve()], }; ``` -------------------------------- ### Install @rollup-extras/plugin-mangle with npm Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-mangle/README.md Use this command to install the plugin as a development dependency. ```bash npm install --save-dev @rollup-extras/plugin-mangle ``` -------------------------------- ### Minimal Rollup Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-size/README.md Basic setup for the plugin in your Rollup configuration file. ```javascript import size from "@rollup-extras/plugin-size"; export default { input: "src/index.js", output: { dir: "dist", format: "es", }, plugins: [size()], }; ``` -------------------------------- ### Terser Minification Example Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Example of how to configure the 'minify' option using the 'terser' library for code minification in emit asset mode. ```javascript import { minify } from 'terser'; scriptLoader({ emit: 'asset', minify: async (code, map) => { const result = await minify(code, { sourceMap: map ? { content: map } : false }); return { code: result.code, map: result.map }; } }) ``` -------------------------------- ### Install Rollup Plugin Html Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-html/README.md Install the plugin using npm. This command adds the plugin as a development dependency to your project. ```bash npm install --save-dev @rollup-extras/plugin-html ``` -------------------------------- ### Rollup Configuration with Imports and Root Directory Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-angularjs-template-cache/README.md Advanced Rollup configuration using `useImports = true` and `rootDir`. This setup requires an additional plugin like `rollup-plugin-html` to handle HTML imports. ```javascript import templatesCache from '@rollup-extras/plugin-angularjs-template-cache'; import htmlImport from 'rollup-plugin-html'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [ htmlImport({include: '**/*.html'}) templatesCache({ templates: './src/**/*.html', rootDir: './src', useImports: true}), ], } ``` -------------------------------- ### Install Rollup Plugin Externals Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-externals/README.md Install the plugin using npm. This command saves the package as a development dependency. ```bash npm install --save-dev @rollup-extras/plugin-externals ``` -------------------------------- ### Configure @rollup-extras/plugin-externals with Zero-Config Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use this zero-configuration setup to automatically externalize all dependencies from `node_modules` and Node.js built-in modules. ```javascript import externals from '@rollup-extras/plugin-externals'; // Zero-config: externalizes all node_modules and Node builtins export default { input: 'src/index.js', output: { format: 'cjs', dir: 'dist' }, plugins: [externals()], }; ``` -------------------------------- ### Basic Rollup Configuration with Html Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-html/README.md Configure Rollup to use the html plugin. This basic setup specifies the input file, output format and directory, and includes the html plugin in the plugins array. ```javascript import html from '@rollup-extras/plugin-html'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [html()], } ``` -------------------------------- ### getOptions Source: https://github.com/kshutkin/rollup-extras/blob/main/utils/README.md Utility function to get options object. It merges options from multiple sources: defaults, user-provided options, and additional factories. It can handle string, string array, or object options. ```APIDOC ## getOptions ### Description Utility function to get options object. It merges options from multiple sources: defaults, user-provided options, and additional factories. It can handle string, string array, or object options. ### Signature ```typescript function getOptions, D, F extends DefaultsFactory & Partial>>, C extends string>(options: T | undefined, defaults: D | undefined, field: C, factory?: F) ``` ### Parameters - `options` (T | undefined) - object passed to the plugin, can be `string`, `string[]` or `undefined` (applied second) - `defaults` (D | undefined) - defaults (applied first) - `field` (C) - `string` to set a property in case options is `string` or `string[]`, if `options[field]` is `string` it will be converted to `string[]` - `factory` (F | undefined) - additional factories (applied last) ``` -------------------------------- ### Basic @rollup-extras/plugin-angularjs-template-cache Configuration Source: https://context7.com/kshutkin/rollup-extras/llms.txt Compile AngularJS HTML templates into an `$templateCache` module. This basic setup reads templates from disk, minifies them using `htmlmin`, and automatically injects the import into the bundle. ```javascript import templatesCache from '@rollup-extras/plugin-angularjs-template-cache'; import htmlImport from 'rollup-plugin-html'; import htmlmin from 'htmlmin'; // Basic: read templates from disk, run through htmlmin, auto-import into bundle export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [ templatesCache({ templates: './src/**/*.html', rootDir: './src', // URI = path relative to rootDir angularModule: 'app', standalone: false, // use existing angular module autoImport: true, // inject import into bundle automatically processHtml: (html) => htmlmin.minify(html, { collapseWhitespace: true }), transformTemplateUri: (uri) => uri.replace(/^\/, ''), // strip leading slash }), ], }; ``` -------------------------------- ### Provide Plugin Options Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Pass options directly to the serve plugin function to customize its behavior. ```javascript serve({ option: value, option2: value2 }); ``` -------------------------------- ### Hybrid In-Memory and Disk Serving Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Configure the plugin to serve bundled assets from memory while serving static files from a specified directory on disk. ```javascript serve({ inMemory: true, dirs: ["public"] }) ``` -------------------------------- ### Basic Rollup Configuration with Plugin Binify Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-binify/README.md Configure Rollup to use the binify plugin for creating CLI entry files. Ensure the output format is compatible with CLI execution. ```javascript import binify from "@rollup-extras/plugin-binify"; export default { input: "src/index.js", output: { format: "cjs", dir: "dest", }, plugins: [binify()], }; ``` -------------------------------- ### Basic Rollup Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Configure Rollup to use the serve plugin with default settings. Ensure 'output.dir' is defined for zero-config operation. ```javascript import serve from "@rollup-extras/plugin-serve"; export default { input: "src/index.js", output: { format: "es", dir: "dest", }, plugins: [serve()], }; ``` -------------------------------- ### Migrate to emit: 'asset' Mode Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Existing users can opt into the new 'asset' emission mode by passing the `emit: 'asset'` option to the scriptLoader function. The default behavior (`emit: 'inline'`) remains unchanged. ```javascript // Before (still works) scriptLoader(); // After (new mode) scriptLoader({ emit: "asset" }); ``` -------------------------------- ### Configure Prebundle Plugin for All Dependencies Source: https://context7.com/kshutkin/rollup-extras/llms.txt In watch mode, this configuration pre-bundles all external npm dependencies into a single chunk. This speeds up development builds by reducing the number of modules Rollup needs to process. ```javascript import prebundle from '@rollup-extras/plugin-prebundle'; // Watch mode only (default): prebundle all node_modules imports export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [prebundle()], }; ``` -------------------------------- ### Enable Prebundle in Build Mode Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-prebundle/README.md Configure the plugin to activate during regular Rollup builds, not just watch mode. ```javascript prebundle({ enableInBuildMode: true }); ``` -------------------------------- ### Configure Mangle Plugin with Custom Prefix Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-mangle/README.md Customize the prefix used by the mangle plugin to identify variables and properties for minification. This example uses '$$' as the prefix. ```javascript mangle('$$') ``` -------------------------------- ### Configure Mangle Plugin with Default Prefix Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use the default configuration to mangle all identifiers and properties starting with '$_'. This is useful for minifying private members in your code. ```javascript import mangle from '@rollup-extras/plugin-mangle'; // Default: mangles all identifiers/properties starting with '$_' export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', plugins: [mangle()], }, }; ``` -------------------------------- ### Clean Output Directories with @rollup-extras/plugin-clean Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use this plugin to automatically clean output directories before each build. It targets `output.dir` by default and can be configured to clean custom directories or run on every watch rebuild. ```javascript import clean from '@rollup-extras/plugin-clean'; // Zero-config: cleans output.dir automatically export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [clean()], }; ``` ```javascript import clean from '@rollup-extras/plugin-clean'; // Clean multiple custom directories; re-clean on every watch rebuild export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [ clean({ targets: ['dist', 'tmp'], deleteOnce: false, // clean on every rebuild (watch mode) verbose: true, }), ], }; ``` -------------------------------- ### Minimal Rollup Configuration with Mangle Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-mangle/README.md Configure Rollup to use the mangle plugin with default settings. The plugin will automatically mangle identifiers and properties starting with '$_'. ```javascript import mangle from '@rollup-extras/plugin-mangle'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', plugins: [mangle()], }, }; ``` -------------------------------- ### Use as Output Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-copy/README.md Configure the plugin to run as an output plugin by setting `outputPlugin` to `true`. Note that watch mode is disabled in this configuration due to Rollup limitations. ```javascript copy({ src: "assets/*", outputPlugin: true }); ``` ```javascript copy({ targets: ["assets/*"], outputPlugin: true }); ``` -------------------------------- ### In-Memory Serving Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Enable in-memory serving to avoid writing files to disk, similar to webpack-dev-server. Recommended to use with `watch.skipWrite: true`. ```javascript import serve from "@rollup-extras/plugin-serve"; export default { input: "src/index.js", output: { format: "es", dir: "dest", }, watch: { skipWrite: true, // recommended: avoid writing files to disk }, plugins: [serve({ inMemory: true })], }; ``` -------------------------------- ### Configure Advanced @rollup-extras/plugin-serve Source: https://context7.com/kshutkin/rollup-extras/llms.txt Fully disk-free dev server with live reload and HTTPS. Supports in-memory serving, live reload via Server-Sent Events, and full Hono middleware customization. ```javascript import serve from '@rollup-extras/plugin-serve'; // Fully disk-free dev server with live reload and HTTPS export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, watch: { skipWrite: true }, plugins: [ serve({ inMemory: true, // serve chunks from memory liveReload: true, // auto-reload browser on rebuild port: 3000, https: { cert: 'localhost.pem', key: 'localhost-key.pem' }, dirs: ['public'], // also serve static files from disk customize: (app) => { // Add custom Hono middleware/routes app.get('/api/health', (c) => c.json({ ok: true })); }, onListen: (server) => { console.log(`Dev server ready on port ${server.address().port}`); return true; // suppress default banner }, }), ], }; ``` -------------------------------- ### Configure Html Plugin with Options Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-html/README.md Pass options directly to the html plugin function to customize its behavior. The returned object is the plugin instance. ```javascript html({option: value, option2: value2}) ``` -------------------------------- ### Get Plugin Options Utility Source: https://github.com/kshutkin/rollup-extras/blob/main/utils/README.md Utility function to process plugin options, handling string, array, or undefined inputs, and merging with defaults and factories. Use when your plugin accepts flexible option formats. ```typescript function getOptions, D, F extends DefaultsFactory & Partial>>, C extends string>(options: T | undefined, defaults: D | undefined, field: C, factory?: F); ``` -------------------------------- ### Recommended User Configuration for Script Loader and HTML Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Configure scriptLoader to emit assets and integrate with the html plugin for template injection. Use combineAssetFactories to manage asset injection order. ```javascript import scriptLoader from "@rollup-extras/plugin-script-loader"; import html from "@rollup-extras/plugin-html"; import { simpleES5Script, combineAssetFactories, } from "@rollup-extras/plugin-html/asset-factories"; export default { input: "src/main.js", output: { format: "es", dir: "dist", sourcemap: true, assetFileNames: "assets/[name].[hash].[ext]", // Rollup's pattern for hashed assets }, plugins: [ scriptLoader({ emit: "asset", name: "vendor.js", exactFileName: false, // Let Rollup apply assetFileNames pattern sourcemap: true, // minify: async (code, map) => { ... } // optional }), html({ template: "index.html", assetsFactory: combineAssetFactories( // Inject vendor bundle as classic script (before module scripts) simpleES5Script(/vendor\..*\.js$/) // ... other asset factories ), }), ], }; ``` -------------------------------- ### multiConfigPluginBase Source: https://github.com/kshutkin/rollup-extras/blob/main/utils/README.md Utility to construct a plugin that should/can be executed when multiple configs are used to gather information for the plugin. It returns a plugin instance. ```APIDOC ## multiConfigPluginBase ### Description Utility to construct a plugin that should/can be executed when multiple configs are used to gather information for the plugin. It returns a plugin instance. ### Signature ```typescript function multiConfigPluginBase(useWriteBundle: boolean, pluginName: string, execute: ExecuteFn): Partial ``` ### Parameters - `useWriteBundle` (boolean) - truthy if `execute` function should be executed on the last `writeBundle`, falsy if it should be executed on `generateBundle` - `pluginName` (string) - plugin name - `execute` (ExecuteFn) - function to execute ### Returns - `Partial` - A plugin instance. ``` -------------------------------- ### Basic Rollup Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-prebundle/README.md Integrate the prebundle plugin into your Rollup configuration for faster development builds. ```javascript import prebundle from "@rollup-extras/plugin-prebundle"; export default { input: "src/index.js", output: { format: "es", dir: "dest", }, plugins: [prebundle()], }; ``` -------------------------------- ### Basic Usage of Rollup Plugin Exec Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-exec/README.md Import and use the plugin in your Rollup configuration. The plugin is called with a callback function that executes after the build. ```javascript import exec from "@rollup-extras/plugin-exec"; export default { input: "src/index.js", output: { format: "es", dir: "dest", }, plugins: [ exec(() => { console.log("finished"); }), ], }; ``` -------------------------------- ### Configure @rollup-extras/plugin-exec with Object Form and Multiple Instances Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use the object form to configure the exec plugin and register additional instances using `api.addInstance()`. This allows for multiple configurations of the same plugin within a single build. ```javascript // Object form — multiple configs: register extra instances via api.addInstance() const execPlugin = exec({ exec() { console.log('all configs done'); } }); export default [configA, { ...configB, plugins: [execPlugin.api.addInstance()] }]; ``` -------------------------------- ### Enable Minification Reporting with esbuild Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-size/README.md Provide a custom minification function using esbuild to report minified sizes. ```javascript import { transform } from "esbuild"; size({ minify: async (_fileName, code) => { const result = await transform(code, { minify: true }); return result.code; }, }); ``` -------------------------------- ### Basic Rollup Configuration with Plugin Clean Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-clean/README.md Integrate the clean plugin into your Rollup configuration. It automatically cleans the directory specified in output.dir. ```javascript import clean from '@rollup-extras/plugin-clean'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [clean()] } ``` -------------------------------- ### Enable Brotli Reporting Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-size/README.md Enable reporting of brotli compressed sizes. ```javascript size({ brotli: true }); ``` -------------------------------- ### Configure @rollup-extras/plugin-size for Size Reporting Source: https://context7.com/kshutkin/rollup-extras/llms.txt Configure the plugin to report raw, minified, and compressed sizes. Persists stats between builds to show size deltas. Supports custom minification logic. ```javascript import size from '@rollup-extras/plugin-size'; import { minify } from 'oxc-minify'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es' }, plugins: [ size({ statsFile: '.build-stats.json', // persisted between runs updateStats: true, gzip: true, brotli: true, minify: async (fileName, code) => { const result = await minify(fileName, code, { compress: { target: 'esnext' }, mangle: { toplevel: true }, codegen: { removeWhitespace: true }, }); return result.code; }, }), ], }; // As output plugin (inside output.plugins) output: { dir: 'dist', format: 'es', plugins: [size({ outputPlugin: true, brotli: true })], } ``` -------------------------------- ### ServePluginOptions Type Definition Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-serve/README.md Defines the structure for configuring the Serve plugin. Options include setting the plugin name, enabling write bundle, in-memory serving, live reloading, specifying directories, port, host, HTTPS certificates, and custom event handlers. ```typescript type ServePluginOptions = { pluginName?: string; useWriteBundle?: boolean; inMemory?: boolean; liveReload?: boolean; dirs?: string | string[]; port?: number; useLogger?: boolean; staticOptions?: object; host?: string; https?: { cert: string; key: string; ca?: string; }; customize?: (app: Hono) => void; onListen?: (server: Server) => void | true; } | string | string[] ``` -------------------------------- ### Script Loader with exactFileName: true Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md When exactFileName is true (the default), the asset is emitted with the exact name specified. ```javascript scriptLoader({ emit: "asset", name: "vendor.js", // exactFileName: true // default }); // → emits: vendor.js ``` -------------------------------- ### Basic Rollup Configuration with Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-strip-comments/README.md Configure Rollup to use the stripComments plugin in the output options. ```javascript import stripComments from '@rollup-extras/plugin-strip-comments'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', plugins: [stripComments()], }, }; ``` -------------------------------- ### Emit Main Asset (Hashing Strategy) Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Emits the main asset, allowing Rollup to apply hashing. The filename is then retrieved to construct the sourcemap filename. ```javascript // 1. Emit main asset WITHOUT sourceMappingURL const refId = this.emitFile({ type: "asset", name: "vendor.js", // Rollup will hash this source: concatenatedCode, }); // 2. Get hashed filename immediately const mainFileName = this.getFileName(refId); // → e.g., "assets/vendor.C_3a_Azj.js" ``` -------------------------------- ### Default @rollup-extras/plugin-binify Configuration Source: https://context7.com/kshutkin/rollup-extras/llms.txt Prepends a shebang line to entry chunk output files and sets executable file permissions, turning a Node.js bundle into a directly invocable CLI binary. Default behavior prepends '#!/usr/bin/env node' and sets chmod 755 on all entry chunks. ```javascript import binify from '@rollup-extras/plugin-binify'; // Default: prepends #!/usr/bin/env node and sets chmod 755 on all entry chunks export default { input: 'src/cli.js', output: { format: 'cjs', dir: 'bin' }, plugins: [binify()], }; ``` -------------------------------- ### Configure Prebundle Plugin for Specific Packages Source: https://context7.com/kshutkin/rollup-extras/llms.txt Pre-bundle only specified packages and enable this functionality in production builds. This is useful for optimizing critical dependencies. ```javascript // Prebundle only specific packages; also activate in production builds prebundle({ packages: ['react', 'react-dom', 'lodash-es'], enableInBuildMode: true, }); ``` -------------------------------- ### Using Html Plugin with Copy Plugin Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-html/README.md Integrate the html plugin with the copy plugin to use an existing HTML file as a template. The copy plugin copies 'src/index.html', which is then used as input for the html plugin. ```javascript import copy from '@rollup-extras/plugin-copy'; import html from '@rollup-extras/plugin-html'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [copy('src/index.html'), html()], }; ``` -------------------------------- ### Copy on Every Rebuild Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-copy/README.md Configure the plugin to copy assets on every rebuild in watch mode by setting `copyOnce` to `false`. This ensures assets are always up-to-date. ```javascript copy({ src: "assets/*", copyOnce: false }); ``` ```javascript copy({ targets: ["assets/*"], copyOnce: false }); ``` -------------------------------- ### Configure @rollup-extras/plugin-externals with Custom Logic Source: https://context7.com/kshutkin/rollup-extras/llms.txt Implement custom logic to force-internalize specific packages or use default externalization rules for others. Set `verbose: true` for detailed logging. ```javascript externals({ external: (id, defaultExternal) => { if (id.includes('my-inlined-dep')) return false; // bundle it return defaultExternal; // use default for everything else }, verbose: true, }); ``` -------------------------------- ### Configure @rollup-extras/plugin-exec to Run Post-Build Scripts Source: https://context7.com/kshutkin/rollup-extras/llms.txt Execute arbitrary callback functions after the bundle completes. This is useful for tasks like running type checks or printing build summaries. The callback receives a Rollup PluginContext with a logger. ```javascript import exec from '@rollup-extras/plugin-exec'; import { execSync } from 'child_process'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [ exec(function () { // `this` is a Rollup PluginContext enriched with a `logger` this.logger.info('Build complete — running type check...'); execSync('tsc --noEmit', { stdio: 'inherit' }); }), ], }; ``` -------------------------------- ### Emit Sourcemap (Hashing Strategy) Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Emits the sourcemap with an exact filename derived from the main asset's hashed name. No additional hashing is applied to the sourcemap file itself. ```javascript // 3. Emit sourcemap with EXACT fileName (derived from main hash) const mapFileName = mainFileName + ".map"; this.emitFile({ type: "asset", fileName: mapFileName, // exact, no additional hashing source: JSON.stringify(sourcemap), }); ``` -------------------------------- ### Configure Inline Mode (Default) Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/README.md Configure the plugin for inline mode, which is the default behavior. This embeds raw script source code directly into the bundle at the import site. ```javascript import scriptLoader from "@rollup-extras/plugin-script-loader"; export default { input: "src/index.js", output: { format: "iife", file: "dist/bundle.js", }, plugins: [scriptLoader()], }; ``` ```javascript // Legacy libraries — inlined in this exact order import "script!d3"; import "script!d3-tip"; import "script!angular"; import "script!angular-route"; import "script!angular-sanitize"; // Your application code (regular ES module imports) import { app } from "./app.js"; app.init(); ``` -------------------------------- ### Custom @rollup-extras/plugin-binify Configuration Source: https://context7.com/kshutkin/rollup-extras/llms.txt Allows customization of the shebang, executable permissions, and filtering of entry chunks for the binify plugin. ```javascript binify({ shebang: '#!/usr/bin/env -S node --experimental-vm-modules', executableFlag: 0o755, filter: (item) => item.type === 'chunk' && item.isEntry && item.fileName === 'cli.js', }); ``` ```javascript binify({ executableFlag: false }); ``` -------------------------------- ### Collect Statistics Efficiently with @rollup-extras/utils Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use the `statistics` utility to collect file statistics, logging either a count or a list of filenames based on a verbose flag. Avoids holding large numbers of filenames in memory. ```javascript import { getOptions, multiConfigPluginBase, statistics } from '@rollup-extras/utils'; // statistics: log count or filenames depending on verbose mode function copyPlugin({ verbose }) { const stats = statistics(verbose, (result) => typeof result === 'number' ? `Copied ${result} files` : `Copied: ${result.join(', ')}` ); // During build: stats('file.js'), stats('other.js'), ... // At end: this.warn(stats()); // → "Copied 2 files" or lists each file if verbose } ``` -------------------------------- ### Configure Asset Mode (Emit Separate File) Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/README.md Configure the plugin to emit all scripts as a separate concatenated asset file. This is useful for legacy code that must run in non-strict mode. ```javascript import scriptLoader from "@rollup-extras/plugin-script-loader"; export default { input: "src/index.js", output: { format: "es", dir: "dist", sourcemap: true, }, plugins: [ scriptLoader({ emit: "asset", name: "vendor.js", sourcemap: true, }), ], }; ``` -------------------------------- ### Flatten Directory Structure Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-copy/README.md Use `flatten: true` to copy all files from the source directory directly into the destination, ignoring their original subdirectory structure. This is useful for consolidating assets. ```javascript copy({ src: "assets/*", flatten: true }); ``` ```javascript copy({ targets: ["assets/*"], flatten: true }); ``` -------------------------------- ### Specify Destination Subfolder and Exclude Files Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-copy/README.md Use the `dest` option to place assets in a subfolder within the output directory, preserving directory structure. The `exclude` option filters out specific files, such as JSON files, from being copied. ```javascript copy({ src: "assets/*", dest: "fonts", exclude: "*.json" }); ``` ```javascript copy({ targets: [{ src: "assets/*", dest: "fonts", exclude: "*.json" }] }); ``` -------------------------------- ### Coordinate Multi-Config Builds with @rollup-extras/utils Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use `multiConfigPluginBase` to execute a callback function exactly once after all Rollup output configurations have completed, typically used for post-build tasks. ```javascript import { getOptions, multiConfigPluginBase, statistics } from '@rollup-extras/utils'; // multiConfigPluginBase: execute once after ALL Rollup configs complete function myMultiPlugin(userOptions) { const base = multiConfigPluginBase( true, // use writeBundle (vs generateBundle) 'my-plugin', function (bundle) { console.log('All outputs written — running post-build tasks'); } ); return { name: 'my-plugin', ...base }; } ``` -------------------------------- ### Emit Sourcemap and Update Main Asset Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-script-loader/EMIT_ASSET_PLAN.md Emits the sourcemap and modifies the main asset to include the sourceMappingURL comment, ensuring it points to the correct hashed sourcemap file. ```javascript if (sourcemap) { // Compute sourcemap filename based on the (possibly hashed) main filename const mapFileName = finalFileName + '.map'; // Emit sourcemap with EXACT fileName (no additional hashing) this.emitFile({ type: 'asset', fileName: mapFileName, source: JSON.stringify(sourcemapGenerator.toJSON()) }); // Modify main asset in bundle to add sourceMappingURL // (bundle mutation after emitFile is supported and persists to output) bundle[finalFileName].source += `\n//# sourceMappingURL=${basename(mapFileName)}`; } ``` -------------------------------- ### Configure Plugin Clean Options Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-clean/README.md Customize plugin behavior with options like `pluginName`, `deleteOnce`, `outputPlugin`, and `verbose`. ```typescript type CleanPluginOptions = { targets?: string | string[], // defaulted to output.dir per output pluginName?: string, // for debugging purposes, default is `@rollup-extras/plugin-clean` deleteOnce?: boolean, // default true outputPlugin?: boolean, // default true verbose?: boolean // default false } | string | string[]; ``` -------------------------------- ### Basic Rollup Configuration Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-angularjs-template-cache/README.md Configure Rollup to use the plugin for basic template caching. Specify the input file, output format and directory, and the glob pattern for HTML templates. ```javascript import templatesCache from '@rollup-extras/plugin-angularjs-template-cache'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [ templatesCache('./views/**/*.html'), ], } ``` -------------------------------- ### Pretty Print HTML with Template Factory Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-html/README.md Customize HTML template rendering using `templateFactory` with an external library like `simply-beautiful` for pretty printing. This allows for more sophisticated HTML generation during the build process. ```javascript import html from '@rollup-extras/plugin-html'; import sb from 'simply-beautiful'; export default { input: 'src/index.js', output: { format: 'es', dir: 'dest' }, plugins: [html({ templateFactory: (template, assets, defaultFactory) => sb.html(defaultFactory(template, assets)) })], }; ``` -------------------------------- ### Normalize Plugin Options with @rollup-extras/utils Source: https://context7.com/kshutkin/rollup-extras/llms.txt Use `getOptions` to normalize plugin call signatures (string, array, object) into a consistent options object. Ensures options like 'targets' are always an array. ```javascript import { getOptions, multiConfigPluginBase, statistics } from '@rollup-extras/utils'; // getOptions: normalize plugin call signatures to a consistent options object function myPlugin(options) { // Converts 'src/*' | ['src/*'] | { targets: 'src/*' } all to { targets: ['src/*'] } const opts = getOptions(options, { verbose: false }, 'targets'); // opts.targets is always string[], opts.verbose is boolean } ``` -------------------------------- ### Prebundle Specific Packages Source: https://github.com/kshutkin/rollup-extras/blob/main/plugin-prebundle/README.md Configure the plugin to only prebundle a specified list of packages. ```javascript prebundle({ packages: ["react", "react-dom"] }); ``` -------------------------------- ### Copy Static Assets with @rollup-extras/plugin-copy Source: https://context7.com/kshutkin/rollup-extras/llms.txt This plugin copies static assets through Rollup's `emitFile` pipeline, supporting glob patterns, watch-mode detection, and optional content hashing. It can also bypass the Rollup pipeline to write directly to disk. ```javascript import copy from '@rollup-extras/plugin-copy'; // Copy all assets, preserve directory structure, watch for changes export default { input: 'src/index.js', output: { format: 'es', dir: 'dist' }, plugins: [ copy({ targets: [ { src: 'assets/images/*', dest: 'images' }, { src: 'assets/fonts/*', dest: 'fonts', exclude: '*.json' }, ], copyOnce: false, // re-copy on every watch rebuild verbose: 'list-filenames', }), ], }; ``` ```javascript copy({ src: 'public/**/*', dest: 'dist/public', emitFiles: false, preserveSymlinks: true, }); ``` ```javascript copy({ src: 'assets/*', exactFileNames: false }); ``` -------------------------------- ### Configure Script Loader Plugin for Asset Mode Source: https://context7.com/kshutkin/rollup-extras/llms.txt Configure the asset mode to emit scripts as separate files, preserving global scope and allowing for true sloppy-mode execution. This mode also supports sourcemaps and minification. ```javascript // Asset mode: emit separate vendor.js for true global/sloppy scope + auto-inject into HTML export default { input: 'src/main.js', output: { format: 'es', dir: 'dist', sourcemap: true, assetFileNames: 'assets/[name].[hash].[ext]' }, plugins: [ scriptLoader({ emit: 'asset', name: 'vendor.js', exactFileName: false, // apply assetFileNames hashing sourcemap: true, minify: async (code, map) => { const result = await minify(code, { sourceMap: map ? { content: map } : false }); return { code: result.code, map: result.map }; }, }), html({ assetsFactory: combineAssetFactories( simpleES5Script(/vendor\..*\.js$/) // inject vendor as classic