Registry / devops / rollup-swc-preserve-directives

rollup-swc-preserve-directives

JSON →
library0.7.0jsnpmunverified

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.

npm install rollup-swc-preserve-directives
INSTALL
IMPORT
SIG · ROLLUP-SWC-PRESERV
R
rollup-swc-preserve-directives
devopsjavascriptv0.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import swcPreserveDirectives from 'rollup-swc-preserve-directives'
const swcPreserveDirectives = require('rollup-swc-preserve-directives')
ESM default export; CJS require() works but not recommended for consistency.
swcPreserveDirectives
import swcPreserveDirectives from 'rollup-swc-preserve-directives'
import { swcPreserveDirectives } from 'rollup-swc-preserve-directives'
Avoid named import; only default export is provided.
type definitions
import type { RollupSwcPreserveDirectivesOptions } from 'rollup-swc-preserve-directives'
Types are shipped but not exported directly; use module augmentation if needed.

Demonstrates basic usage of rollup-swc-preserve-directives plugin in a Rollup config to preserve directives during bundling.

import swcPreserveDirectives from 'rollup-swc-preserve-directives'; import { defineConfig } from 'rollup'; export default defineConfig({ input: 'src/index.js', output: { dir: 'dist', format: 'esm' }, plugins: [ swcPreserveDirectives() ] });
Debug
Known issues
breakingSWC version mismatch can cause parse errors or unexpected behavior.
fix
Use @swc/core version compatible with the SWC version used by this plugin; check package.json peerDependencies.
affects: >=0.7.0
deprecatedRollup <4 support may be dropped in future versions.
fix
Upgrade Rollup to ^4.0.0 if encountering issues, or pin to older plugin version.
affects: >=0.6.0
gotchaPlugin only works with Rollup's JavaScript plugins; if using TypeScript, ensure SWC is configured separately for type stripping.
fix
Use @rollup/plugin-typescript or @rollup/plugin-sucrase for TS before this plugin.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module '@swc/core'
@swc/core is not installed or not in node_modules.
fix
Run `npm install @swc/core` in your project directory.
TypeError: swcPreserveDirectives is not a function
Using named import instead of default import.
fix
Use `import swcPreserveDirectives from 'rollup-swc-preserve-directives'` (no curly braces).
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency: requires Rollup >=2 || >=3 || >=4 to function as a plugin.
@swc/corerequiredRuntime dependency: uses SWC to parse and transform code for directive preservation.
Agent activity
6 hits · last 30 days
node
6
Resources
rollup-swc-preserve-directives — npm install rollup-swc-preserve-directives · libregistry