{"id":22229,"library":"rollup-plugin-static-import","title":"rollup-plugin-static-import","description":"Rollup plugin that copies imported files (e.g., SVG, SCSS) to the output directory while marking them as external in the bundle. Version 1.0.0 rewrites in TypeScript with type declarations. Best used with rollup's preserveModules option to keep imports tree-shakable. Unlike generic copy plugins, it integrates with rollup's watch mode and handles asset re-imports. Requires rollup ^1.20.0 || ^2.0.0 || ^3.0.0.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mefu/rollup-plugin-static-import","tags":["javascript","typescript"],"install":[{"cmd":"npm install rollup-plugin-static-import","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-static-import","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-static-import","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin API used","package":"rollup","optional":false}],"imports":[{"note":"ESM-only; CommonJS require will fail because the package exports only ESM since v1.0.0. Use dynamic import or configure bundler to handle it.","wrong":"const staticImport = require('rollup-plugin-static-import')","symbol":"default","correct":"import staticImport from 'rollup-plugin-static-import'"},{"note":"Type-only export; importing as value will be undefined at runtime. Use 'import type' in TypeScript.","wrong":"import { StaticImportOptions } from 'rollup-plugin-static-import'","symbol":"StaticImportOptions","correct":"import type { StaticImportOptions } from 'rollup-plugin-static-import'"},{"note":"rollup-plugin-static-import does not re-export rollup types; get Plugin from rollup itself.","wrong":"import { Plugin } from 'rollup-plugin-static-import'","symbol":"Plugin","correct":"import { Plugin } from 'rollup'"}],"quickstart":{"code":"// rollup.config.js\nimport staticImport from 'rollup-plugin-static-import';\n\nexport default {\n  input: 'src/index.js',\n  preserveModules: true,\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    staticImport({\n      include: ['src/**/*.svg', 'src/**/*.scss'],\n      exclude: ['src/**/*.test.*'],\n      baseDir: 'src'\n    })\n  ]\n};\n","lang":"javascript","description":"Configures rollup to copy SVG and SCSS files from src to dist, marking them as external so the consuming app bundles them."},"warnings":[{"fix":"Set preserveModules: true in rollup config.","message":"Using staticImport without preserveModules: true may produce non-tree-shakable bundles where all assets are inlined into a single chunk.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always provide include with at least one glob pattern.","message":"The 'include' option is required; omitting it will cause a runtime error.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use dynamic import() or configure your bundler to handle ESM. If using CommonJS, stay on v0.x.","message":"v1.0.0 switched to ESM-only output. CommonJS require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Set baseDir to the directory relative to which you want files copied. Default is 'src'.","message":"Plugin copies files based on import paths relative to baseDir; incorrect baseDir leads to wrong output paths.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import syntax in your config file (if rollup supports it) or switch to dynamic import: const staticImport = (await import('rollup-plugin-static-import')).default;","cause":"Package is ESM-only since v1.0.0; CommonJS require() cannot load it.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/rollup-plugin-static-import/dist/index.js from /path/to/rollup.config.js not supported."},{"fix":"Use default import: import staticImport from 'rollup-plugin-static-import'","cause":"Named import instead of default import: import { staticImport } from 'rollup-plugin-static-import'","error":"TypeError: staticImport is not a function"},{"fix":"Verify that include patterns match files relative to projectRoot (default cwd) or adjust projectRoot option.","cause":"include globs matched no files, or baseDir/resolveRoot misconfigured.","error":"The plugin staticImport did not output any files under output dir. (No files to copy?)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}