nextjs-locator-swc
v0.3.0
Published
Compile-time source attribute injection for nextjs-locator. Babel plugin that adds data-locator-source to JSX elements.
Maintainers
Readme
nextjs-locator-swc
Compile-time source attribute injection for nextjs-locator.
This optional companion package adds data-locator-source attributes to your JSX elements at build time, making Alt+Click source resolution instant — no runtime source map fetching needed.
How It Works
- A Babel plugin runs during compilation and injects
data-locator-source="filepath:line:col"into every JSX element - At runtime,
nextjs-locatorreads these attributes directly instead of fetching and parsing source maps - Result: zero-latency source file opening on first click
Installation
npm install nextjs-locator nextjs-locator-swcUsage
Option 1: Next.js Config Wrapper (Recommended)
// next.config.js
const { withLocator } = require('nextjs-locator-swc');
module.exports = withLocator({
// your existing Next.js config
});Option 2: Babel Plugin Directly
// babel.config.js
module.exports = {
plugins: [
require('nextjs-locator-swc/babel-plugin'),
],
};Options
withLocator(nextConfig, options)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| devOnly | boolean | true | Only inject attributes in development mode |
| attribute | string | 'data-locator-source' | Custom attribute name |
Babel Plugin Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| attribute | string | 'data-locator-source' | Custom attribute name |
Note
Using this package adds a Babel transform step to your build. This means:
- SWC will still handle most transforms, but
.tsx/.jsxfiles will also pass through Babel for attribute injection - Build times may increase slightly in development
- Production builds are unaffected when
devOnly: true(default)
Requirements
- Next.js >= 13.0.0
- nextjs-locator >= 0.3.0
License
MIT
