{"id":22316,"library":"rollup-swc-preserve-directives","title":"rollup-swc-preserve-directives","description":"Rollup plugin that uses SWC to preserve directives such as shebang and string directives (e.g., 'use strict', 'use asm') in bundled output. Version 0.7.0 is the latest stable; updated on demand. It integrates with Rollup build pipeline to ensure important code-level annotations are not stripped during minification or transformation, unlike naive bundlers. Differentiates itself by being SWC-based (fast, Rust-powered) and designed specifically for directive preservation.","status":"active","version":"0.7.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","rollup","plugin","swc","preserve","directives","typescript"],"install":[{"cmd":"npm install rollup-swc-preserve-directives","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-swc-preserve-directives","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-swc-preserve-directives","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: requires Rollup >=2 || >=3 || >=4 to function as a plugin.","package":"rollup","optional":false},{"reason":"Runtime dependency: uses SWC to parse and transform code for directive preservation.","package":"@swc/core","optional":false}],"imports":[{"note":"ESM default export; CJS require() works but not recommended for consistency.","wrong":"const swcPreserveDirectives = require('rollup-swc-preserve-directives')","symbol":"default","correct":"import swcPreserveDirectives from 'rollup-swc-preserve-directives'"},{"note":"Avoid named import; only default export is provided.","wrong":"import { swcPreserveDirectives } from 'rollup-swc-preserve-directives'","symbol":"swcPreserveDirectives","correct":"import swcPreserveDirectives from 'rollup-swc-preserve-directives'"},{"note":"Types are shipped but not exported directly; use module augmentation if needed.","wrong":null,"symbol":"type definitions","correct":"import type { RollupSwcPreserveDirectivesOptions } from 'rollup-swc-preserve-directives'"}],"quickstart":{"code":"import swcPreserveDirectives from 'rollup-swc-preserve-directives';\nimport { defineConfig } from 'rollup';\n\nexport default defineConfig({\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  },\n  plugins: [\n    swcPreserveDirectives()\n  ]\n});","lang":"javascript","description":"Demonstrates basic usage of rollup-swc-preserve-directives plugin in a Rollup config to preserve directives during bundling."},"warnings":[{"fix":"Use @swc/core version compatible with the SWC version used by this plugin; check package.json peerDependencies.","message":"SWC version mismatch can cause parse errors or unexpected behavior.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Upgrade Rollup to ^4.0.0 if encountering issues, or pin to older plugin version.","message":"Rollup <4 support may be dropped in future versions.","severity":"deprecated","affected_versions":">=0.6.0"},{"fix":"Use @rollup/plugin-typescript or @rollup/plugin-sucrase for TS before this plugin.","message":"Plugin only works with Rollup's JavaScript plugins; if using TypeScript, ensure SWC is configured separately for type stripping.","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":"Run `npm install @swc/core` in your project directory.","cause":"@swc/core is not installed or not in node_modules.","error":"Error: Cannot find module '@swc/core'"},{"fix":"Use `import swcPreserveDirectives from 'rollup-swc-preserve-directives'` (no curly braces).","cause":"Using named import instead of default import.","error":"TypeError: swcPreserveDirectives is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}