Registry / devops / rollup-preserve-directives

rollup-preserve-directives

JSON →
library1.1.3jsnpmunverified

Rollup plugin to preserve shebang and string directives (e.g., 'use strict') in bundled output. Current stable version 1.1.3, maintained actively. No external dependencies, ships TypeScript types. Key differentiator: handles shebang and directives that Rollup's tree-shaking may remove, and exposes metadata for inter-plugin communication. Renamed from rollup-swc-preserve-directives in v1.0.0.

npm install rollup-preserve-directives
INSTALL
IMPORT
SIG · ROLLUP-PRESERVE-DI
R
rollup-preserve-directives
devopsjavascriptv1.1.3
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 preserveDirectives from 'rollup-preserve-directives'
const preserveDirectives = require('rollup-preserve-directives')
ESM-only package; CJS require is not supported.
type PreserveDirectivesOptions
import type { PreserveDirectivesOptions } from 'rollup-preserve-directives'
Type import for TypeScript users only.
type PluginMeta
import type { PluginMeta } from 'rollup-preserve-directives'
Type for the metadata exposed via moduleParsed hook.

Basic rollup.config.js configuration showing how to use the plugin to preserve shebang and directives.

import preserveDirectives from 'rollup-preserve-directives'; export default { input: './src/index.js', output: { file: './dist/index.js', format: 'cjs', }, plugins: [ preserveDirectives(), ], };
Debug
Known issues
breakingPackage renamed from rollup-swc-preserve-directives to rollup-preserve-directives in v1.0.0. Old package deprecated.
fix
Uninstall old package: npm uninstall rollup-swc-preserve-directives. Install new: npm install rollup-preserve-directives. Update import.
affects: <1.0.0
breakingv1.0.0 dropped dependency on swc/core. Plugin now uses Rollup's built-in parser only.
fix
No change needed unless you relied on swc-specific behavior. Remove any swc options from plugin call.
affects: >=1.0.0
deprecatedv0.x versions (under old name rollup-swc-preserve-directives) are deprecated and receive no updates.
fix
Upgrade to v1.0.0+ and rename package.
affects: <1.0.0
gotchaPlugin only works with Rollup's ESM configuration files (rollup.config.mjs or type: module).
fix
Ensure your config file uses ES module syntax (export default) and has .mjs extension or package.json type: module.
affects: >=1.0.0
gotchaMay not preserve directives in all cases; if you rely on specific directives being kept, verify output.
fix
Use this.getModuleInfo or moduleParsed hook to check directives metadata.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token 'export'
Using require() to import an ES module package.
fix
Use import syntax or rename config file to .mjs.
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rollup-preserve-directives'
Package not installed or mismatched version.
fix
Run npm install rollup-preserve-directives.
TypeError: preserveDirectives is not a function
Default import error, possibly using named import instead of default.
fix
Use import preserveDirectives from 'rollup-preserve-directives' (default import).
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
rollup-preserve-directives — npm install rollup-preserve-directives · libregistry