{"id":22088,"library":"rollup-plugin-insert","title":"rollup-plugin-insert","description":"A Rollup plugin for string mutation operations on file contents: append, prepend, wrap, and custom transforms. Current stable version is 1.3.2 (last released March 2021). The plugin supports MagicString for source map-aware transformations, ships TypeScript types, and operates in maintenance mode with no recent activity. Key differentiators include separate importable functions, optional source map support, and file filtering via include/exclude patterns. Unlike general-purpose plugins like rollup-plugin-string, it focuses specifically on string insertion/wrapping transforms.","status":"maintenance","version":"1.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/rx-ts/rollup","tags":["javascript","typescript"],"install":[{"cmd":"npm install rollup-plugin-insert","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-insert","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-insert","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; the plugin requires Rollup's plugin API and MagicString","package":"rollup","optional":false}],"imports":[{"note":"append is a named export, not a default export.","wrong":"import append from 'rollup-plugin-insert'","symbol":"append","correct":"import { append } from 'rollup-plugin-insert'"},{"note":"CommonJS require() works but ESM with named import is recommended.","wrong":"const prepend = require('rollup-plugin-insert').prepend","symbol":"prepend","correct":"import { prepend } from 'rollup-plugin-insert'"},{"note":"wrap is a named export; no common wrong usage.","wrong":"","symbol":"wrap","correct":"import { wrap } from 'rollup-plugin-insert'"},{"note":"Default import exists but not recommended; use named imports for tree-shaking.","wrong":"import insert from 'rollup-plugin-insert'; const transform = insert.transform","symbol":"transform","correct":"import { transform } from 'rollup-plugin-insert'"}],"quickstart":{"code":"// rollup.config.js\nimport { append, prepend, wrap, transform } from 'rollup-plugin-insert';\n\nexport default {\n  input: 'src/main.js',\n  output: { file: 'dist/bundle.js', format: 'iife' },\n  plugins: [\n    append('\\n// Appended footer'),\n    prepend('// Prepended header\\n'),\n    wrap('/* start */', '/* end */'),\n    transform((magicString, code, id) => code.toUpperCase()),\n  ],\n};","lang":"javascript","description":"Shows usage of all four main functions (append, prepend, wrap, transform) in a Rollup config."},"warnings":[{"fix":"Always return a value from transform callback, e.g., code or magicString.toString()","message":"Transform callback must return a string or MagicString; returning undefined silently removes output.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider migrating to alternative plugins like rollup-plugin-string or @rollup/plugin-replace if using Rollup 4+.","message":"The plugin has not been updated since 2021; relies on older Rollup versions (<4).","severity":"deprecated","affected_versions":">=1.3.2"},{"fix":"Explicitly set { sourceMap: false } in the options object if not needed.","message":"Source map is enabled by default and may cause memory issues with large files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use correct signature: append('string', { include: '**/*.txt' })","message":"Include/exclude patterns are not applied to the options object but as a separate argument.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use named imports: import { append } from 'rollup-plugin-insert'","cause":"Using default import instead of named import; default import is an object with methods.","error":"TypeError: insert.append is not a function"},{"fix":"Run npm install --save-dev rollup-plugin-insert","cause":"Plugin not installed or missing from dependencies.","error":"Error: Could not resolve 'rollup-plugin-insert'"},{"fix":"Use named import: import { transform } from 'rollup-plugin-insert'","cause":"Accessing .transform on the default export incorrectly.","error":"TypeError: Cannot read property 'transform' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}