MCPcopy Index your code
hub / github.com/devongovett/unplugin-parcel-macros

github.com/devongovett/unplugin-parcel-macros @v0.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.0 ↗ · + Follow
87 symbols 148 edges 17 files 3 documented · 3% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

unplugin-parcel-macros

An Unplugin that lets you use Parcel's macro implementation in webpack, Vite, Rollup, esbuild, Next.js, and more.

Macros are JavaScript functions that run at build time. The value returned by a macro is inlined into the bundle in place of the original function call. This allows you to generate constants, code, and even additional assets without any custom plugins.

Macros are imported using an import attribute to indicate that they should run at build time rather than being bundled into the output. You can import any JavaScript or TypeScript module as a macro, including built-in Node modules and packages from npm.

Example

This example uses the regexgen library to generate an optimized regular expression from a set of strings at build time.

import regexgen from 'regexgen' with {type: 'macro'};

const regex = regexgen(['foobar', 'foobaz', 'foozap', 'fooza']);
console.log(regex);

This compiles to the following bundle:

console.log(/foo(?:zap?|ba[rz])/);

As you can see, the regexgen library has been completely compiled away, and we are left with a static regular expression!

Setup

webpack

// webpack.config.js
const macros = require('unplugin-parcel-macros');

module.exports = {
  // ...
  plugins: [
    macros.webpack()
  ]
};

Next.js

// next.config.js
const macros = require('unplugin-parcel-macros');

// Create a single instance of the plugin that's shared between server and client builds.
let plugin = macros.webpack();

module.exports = {
  webpack(config) {
    config.plugins.push(plugin);
    return config;
  }
};

Vite

// vite.config.js
import macros from 'unplugin-parcel-macros';

export default {
  plugins: [
    macros.vite()
  ]
};

Rollup

// rollup.config.js
import macros from 'unplugin-parcel-macros';

export default {
  plugins: [
    macros.rollup()
  ]
};

Esbuild

import {build} from 'esbuild';
import macros from 'unplugin-parcel-macros';

build({
  plugins: [
    macros.esbuild()
  ]
});

Extension points exported contracts — how you extend this code

FileSystem (Interface)
(no doc) [1 implementers]
index.d.ts
JsFileSystemOptions (Interface)
(no doc)
index.d.ts
ResolveOptions (Interface)
(no doc)
index.d.ts
FilePathCreateInvalidation (Interface)
(no doc)
index.d.ts
FileNameCreateInvalidation (Interface)
(no doc)
index.d.ts

Core symbols most depended-on inside this repo

get
called by 19
src/resolver.rs
assertNoneState
called by 4
wasm.mjs
_createResolver
called by 3
PackageManager.js
isMusl
called by 3
index.js
load
called by 2
PackageManager.js
resolve
called by 2
PackageManager.js
resolveInternal
called by 2
PackageManager.js
normalizeSeparators
called by 2
PackageManager.js

Shape

Function 34
Method 23
Class 19
Interface 9
Enum 2

Languages

TypeScript55%
Rust45%

Modules by API surface

src/resolver.rs23 symbols
PackageManager.js16 symbols
src/lib.rs15 symbols
index.d.ts12 symbols
unplugin-macros.js7 symbols
wasm.mjs5 symbols
examples/vite/counter.js2 symbols
index.js1 symbols
examples/vite/macro.js1 symbols
examples/next/next.config.mjs1 symbols
examples/next/macro.js1 symbols
examples/next/app/page.tsx1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add unplugin-parcel-macros \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact