Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
default export
✓ import keywords from 'unplugin-keywords'
✗ const keywords = require('unplugin-keywords')
Package is ESM-only; CommonJS require will fail.
Vite plugin
✓ keywords.vite({ ... })
✗ keywords({ ... })
Use .vite() method for Vite, not direct call.
Rollup plugin
✓ keywords.rollup({ ... })
✗ import { rollup } from 'unplugin-keywords'
Access as method on default export, not named import.
Webpack plugin
✓ keywords.webpack({ ... })
✗ new keywords.WebpackPlugin()
Use .webpack() method, not constructor.
Shows how to configure the plugin in Vite with keyword replacements and file filters.
// vite.config.js
import { defineConfig } from 'vite';
import keywords from 'unplugin-keywords';
export default defineConfig({
plugins: [
keywords.vite({
keywords: {
'myVariable': '__obfuscated_1__',
'http://example.com': '__url_1__'
},
exclude: ['node_modules'],
include: ['src/**/*.js']
})
]
});
Debug
Known issues
breakingVersion 2.0 changed plugin API from object with methods to default export with methodsfixReplace `import { viteKeywords } from 'unplugin-keywords'` with `import keywords from 'unplugin-keywords'; keywords.vite()` affects: >=2.0.0
gotchaKeyword replacements are only applied to string literals, not identifiers or commentsfixEnsure target strings are quoted in source code.
affects: >=1.0.0
breakingDrop support for Node 14 in v2.17.0affects: >=2.17.0
deprecatedThe 'regex' option in <2.17.0 is deprecated, use 'pattern' insteadfixRename 'regex' to 'pattern' in config.
affects: >=2.0.0, <2.17.0
Errors
Common errors & fixes
Error: Cannot find module 'unplugin-keywords'
Package not installed or import path incorrect
fixRun `npm install unplugin-keywords` and ensure import is `import keywords from 'unplugin-keywords'`
TypeError: keywords.vite is not a function
Using default import from old version or wrong import pattern
fixUpdate to v2+ and use `import keywords from 'unplugin-keywords'`
ReferenceError: require is not defined in ES module scope
Using require() in ESM context
fixReplace `const keywords = require('unplugin-keywords')` with `import keywords from 'unplugin-keywords'` Error: [unplugin-keywords] 'keywords' option must be an object
Passed non-object as keywords parameter
fixProvide a plain object with string keys and values.
Audit
Dependencies
svelteoptionalRequired peer dependency for Svelte integration