Registry / devops / unplugin-parcel-macros

unplugin-parcel-macros

JSON →
library0.2.0jsnpmunverified

Unplugin plugin that brings Parcel's macro system to webpack, Vite, Rollup, esbuild, Next.js, and more. Macros are JavaScript/TypeScript functions that execute at build time, returning values that get inlined into the bundle, enabling compile-time computation, code generation, and asset creation without custom plugins. Version 0.2.0, actively maintained, requires Node >= 18 and an import attribute (with {type: 'macro'}). Compared to babel macros or webpack loader-based approaches, it leverages Unplugin for universal integration and follows the TC39 import attributes proposal.

npm install unplugin-parcel-macros
INSTALL
IMPORT
SIG · UNPLUGIN-PARCEL-MA
U
unplugin-parcel-macros
devopsjavascriptv0.2.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 macros from 'unplugin-parcel-macros'
const macros = require('unplugin-parcel-macros')
ESM-only; default export is an object with .webpack(), .vite(), .rollup(), .esbuild() methods.
webpack
macros.webpack()
macros.webpack
Call the method to get the plugin instance. Used in both plain Webpack and Next.js.
vite
macros.vite()
macros.vite
Call the method to get the Vite plugin.

Shows how to add the Vite plugin and use a macro with the import attribute to generate a regex at build time.

// vite.config.js import macros from 'unplugin-parcel-macros'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ macros.vite() ] }); // src/index.js import regexgen from 'regexgen' with { type: 'macro' }; const regex = regexgen(['foo', 'bar', 'baz']); export default regex;
Debug
Known issues
gotchaImport attributes syntax (with {type: 'macro'}) is not supported in older bundlers or Node versions without transpilation.
fix
Ensure your toolchain supports the syntax or use a transpiler like SWC or Babel that strips the attribute.
affects: < Node 18, bundlers without import attributes support
breakingMacros must be imported with the exact attribute with {type: 'macro'}. Using a non-standard syntax like assert {type: 'macro'} will not work.
fix
Use with {type: 'macro'} as per the import attributes proposal.
affects: all
gotchaThe macro module is executed at build time and cannot access runtime variables from the calling module.
fix
Ensure macro arguments are compile-time constants or expressions evaluable at build time.
affects: all
deprecatedImport attributes are still a Stage 3 proposal and may change in the future.
fix
Keep the library updated to adapt to spec changes.
affects: all
Errors
Common errors & fixes
Error: require() of ES Module not supported
Using require() to import the ESM-only package
fix
Use import syntax or convert your project to ESM (type:'module' in package.json).
Missing: with {type: 'macro'} - Unexpected token
The import attribute syntax is not parsed by the current bundler/transpiler
fix
Use a tool that supports import attributes (e.g., Node >= 18, modern bundlers) or transpile with SWC/Babel plugin.
Error: Cannot find module 'unplugin-parcel-macros'
Package not installed
fix
Run npm install unplugin-parcel-macros --save-dev
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
unpluginrequiredUnplugin is the core library providing the plugin interface for all bundlers
Agent activity
2 hits · last 30 days
node
2
Resources
unplugin-parcel-macros — npm install unplugin-parcel-macros · libregistry