LocatorJS Documentation
repository·master·Indexed 23 days ago
https://github.com/infi-pc/locatorjsA developer tool that enables click-to-source functionality, allowing users to click a UI component in the browser to open its source code in an IDE. Includes the @locator/webpack-loader for Webpack and Turbopack, specifically designed for environments with restricted Babel plugin access like Next.js projects using SWC. Supports React, Preact, and SolidJS.
What's inside LocatorJS
- LocatorJS is a developer tool that allows you to click on a UI component directly in your browser to automatically open its corresponding source code in your IDE. This streamlines the workflow between visual debugging and code editing.
Requirements for LocatorJS to work
masterLocatorJS works automatically in development mode for most modern stacks (NextJS, Create React App, Vite, etc.).
To function correctly, your project must include
babel-plugin-transform-react-jsx-source(often included viababel-preset-react). Non-Babel stacks use similar alternatives to provide source information. If your environment does not provide this, you must set it up manually.How @locator/webpack-loader works
masterThe loader enables component location tracking by using Babel's transform API to apply the
@locator/babel-jsxplugin to JSX/TSX files.It works by:
- Parsing JSX/TSX files via Babel.
- Adding
data-locatorjsattributes containing the full file path and location (e.g.,data-locatorjs="/path/to/file.tsx:line:column"). - Returning transformed code with sourcemaps.
Key Benefits:
- Server Components Support: Unlike other methods, it does not require
window.__LOCATOR_DATA__, making it compatible with React Server Components where JavaScript execution is limited. - Automatic Filtering: It automatically skips
node_modulesand middleware files. - Framework Compatibility: Works with React, Preact, and SolidJS.
Preserve component state during HMR
masterHot Module Replacement (HMR) in this template does not preserve local component state by default due to the inherent complexities of state preservation in Svelte HMR plugins.
To ensure important data is not lost when a component reloads during development, move that state into an external Svelte store. External stores reside outside the component lifecycle and are not replaced when the component is re-rendered via HMR.
// store.js // An extremely simple external store import { writable } from 'svelte/store' export default writable(0)Configure Next.js 15+ with Turbopack
masterTo use LocatorJS with Next.js 15+ using Turbopack, add the loader to the
turbopack.rulessection in yournext.config.tsornext.config.js. Target.tsxand.jsxfiles.import type { NextConfig } from "next"; const nextConfig: NextConfig = { turbopack: { rules: { "**/*.{tsx,jsx}": { loaders: [ { loader: "@locator/webpack-loader", options: { env: "development", }, }, ], }, }, }, }; export default nextConfig;Set up a Svelte + Vite project
masterThis template provides a minimal starting point for developing with Svelte using Vite. It is designed to provide a good developer experience with Hot Module Replacement (HMR) and Intellisense while remaining lightweight.
If you require a full-featured framework with routing and serverless capabilities, consider using SvelteKit instead. This template is structured similarly to SvelteKit to facilitate easy migration if your project requirements grow.
Setup the Vite + Solid template
masterTo use this template, clone the repository and install dependencies using your preferred package manager. While a
pnpm-lock.yamlis included because dependencies are maintained viapnpm, you can usenpmoryarninstead. If you use a different package manager, you can safely remove thepnpm-lock.yamlfile.$ npm install # or pnpm install or yarn installInstall @locator/webpack-loader
masterInstall the
@locator/webpack-loaderpackage as a development dependency using your preferred package manager.npm install --save-dev @locator/webpack-loader # or yarn add -D @locator/webpack-loader # or pnpm add -D @locator/webpack-loaderRun the Next.js development server
masterTo start the development server for this Next.js project, use your preferred package manager to run the
devscript. Once running, you can view the application athttp://localhost:3000.npm run dev # or yarn dev # or pnpm dev # or bun devConfigure Next.js with Webpack or SWC
masterFor Next.js projects using Webpack (or those using SWC), inject the loader into the
webpackconfiguration function withinnext.config.js. Ensure the loader is only applied to the client-side (!isServer) to avoid issues with server-side rendering.module.exports = { webpack: (config, { isServer }) => { if (!isServer) { config.module.rules.push({ test: /\.(tsx|ts|jsx|js)$/, exclude: /node_modules/, use: [ { loader: "@locator/webpack-loader", options: { env: "development", }, }, ], }); } return config; }, };Run the Vite + Solid app in development mode
masterStart the development server to view your application. The app will be available athttp://localhost:3000and will automatically reload when you make changes to the code.Deploy the Vite + Solid app
masterOnce the production build is complete, you can deploy the contents of thedistfolder to any static host provider (such as Netlify, Surge, or Vercel/Now).