click-to-source
v1.0.8
Published
Hold a configurable hotkey and click any UI element in development to open its source in your editor
Maintainers
Readme
click-to-source
Hold your configured hotkey to preview an element, then click to open its source in your editor.
Works by injecting a data-click-to-source attribute at build time, then using a runtime hover/click handler to preview and open the file at the right line and column.
Validation Status
Currently validated in automated tests:
- Vite React dev/build flow, including source line accuracy
- Vite Vue dev/build flow
- Vite Svelte dev/build flow
- Angular dev-server template injection for external HTML templates
- CLI setup for React, Vue, Svelte, and Angular project shapes
- Runtime hotkey preview highlighting and delayed initialization when instrumented DOM appears after boot
- Open-file endpoint security and Windows editor launching
Manually validated across the checked-in examples:
- React example
- Vue example
- Svelte example
- Angular example
- Webpack React example
- Rspack React example
Implemented, but not yet validated end-to-end in CI:
- Webpack
- Rspack
- Editor behavior outside the current VS Code-focused coverage
- Monorepo and
allowOutsideWorkspacescenarios
Integrations
- Vite React with
react()plusclickToSourceReact() - Vite Vue
- Vite Svelte
- Webpack and Rspack integrations
- Angular dev-server integration
- VS Code, Cursor, and WebStorm launch targets
Install
npm install -D click-to-sourceQuick Start
npx click-to-source setupThis will:
- Add
import "click-to-source/init";to your entry file. - Patch
vite.config.*orangular.jsonwhen detected.
If it cannot safely patch your config, it prints manual steps.
Then start your dev server, hold the configured hotkey to preview a rendered element, and click to open it.
Expected behavior:
- The DOM includes
data-click-to-source="path:line:column"on elements. - Holding the configured hotkey previews the hovered element with a visible outline.
- Clicking while the configured hotkey is held opens the matching file in your editor.
Vite
React
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { clickToSourceReact } from "click-to-source/vite";
export default defineConfig({
plugins: [
react(),
clickToSourceReact({
// Optional: allow opening files outside project root (monorepos).
allowOutsideWorkspace: false,
// Optional: allow requests from non-localhost clients.
allowRemote: false,
}),
],
});clickToSourceReact() is additive for Vite React. Keep your normal react() plugin.
// main.tsx
import "click-to-source/init";The React, Vue, and Svelte paths below are all validated in automated smoke tests.
Vue
// vite.config.ts
import { defineConfig } from "vite";
import { clickToSourceVue } from "click-to-source/vite";
export default defineConfig({
plugins: [clickToSourceVue()],
});// main.ts
import "click-to-source/init";Svelte
// vite.config.ts
import { defineConfig } from "vite";
import { clickToSourceSvelte } from "click-to-source/vite";
export default defineConfig({
plugins: [clickToSourceSvelte()],
});// main.ts
import "click-to-source/init";Webpack
React (Babel)
// .babelrc
{
"plugins": ["click-to-source/babel"]
}// entry file
import "click-to-source/init";Vue (vue-loader)
// webpack.config.js
const { withClickToSource } = require("click-to-source/webpack");
module.exports = withClickToSource({
// your existing config
});Svelte (svelte-loader)
// webpack.config.js
const { withClickToSource } = require("click-to-source/webpack");
module.exports = withClickToSource({
// your existing config
});Rspack
// rspack.config.js
const { withClickToSource } = require("click-to-source/rspack");
module.exports = withClickToSource({
// your existing config
});Angular (dev server)
This uses a custom dev-server builder to inject data-click-to-source into templates.
// angular.json (serve builder)
{
"projects": {
"your-app": {
"architect": {
"serve": {
"builder": "click-to-source:dev-server",
"options": {
"clickToSource": {
"enabled": true
}
}
}
}
}
}
}// src/main.ts
import "click-to-source/init";Notes:
- External HTML templates are supported. Inline templates may not include
data-click-to-source. - This is dev-only. Production builds are unaffected.
Examples
Checked-in example apps live in:
examples/react-exampleexamples/vue-exampleexamples/svelte-exampleexamples/angular-exampleexamples/webpack-react-exampleexamples/rspack-react-example
Each example is intended to build locally and reflect the currently supported setup shape. All six examples were manually validated locally. Webpack and Rspack are not yet covered by the automated smoke suite.
Configuration
import { configManager } from "click-to-source";
configManager.updateConfig({
hotkey: "alt",
position: "tr",
theme: "dark",
enabled: true,
});Config options:
interface ClickToSourceConfig {
enabled: boolean;
hotkey: "ctrl" | "alt" | "meta" | "shift";
position: "tl" | "tr" | "bl" | "br";
theme: "light" | "dark" | "auto";
showButton: boolean;
serverPath: string;
serverBaseUrl?: string;
openIn: "vscode" | "cursor" | "webstorm";
}Server Security Defaults
The open-file endpoint is locked down by default:
- Only
GETis accepted. - Only loopback requests (
127.0.0.1/::1) are accepted. - Cross-origin browser requests are blocked.
- Paths outside
process.cwd()are blocked.
For monorepos or remote-device workflows, you can opt in:
clickToSourceReact({
allowOutsideWorkspace: true,
allowRemote: true,
});Angular builder options:
{
"clickToSource": {
"enabled": true,
"allowOutsideWorkspace": false,
"allowRemote": false
}
}How It Works
- Build time: A framework-specific transform injects
data-click-to-source="path:line:column"into element tags. - Runtime: Holding the configured hotkey previews the hovered instrumented element, and clicking opens your editor at that location.
- Dev server: A lightweight endpoint triggers
code --goto(or other editors).
Troubleshooting
If clicking does nothing:
- Confirm the build transform is enabled (Vite plugin or Babel plugin).
- Ensure
import "click-to-source/init";is in your entry file. - Check that your editor command is available on PATH (e.g.,
code --version). - If source files are outside your app root, set
allowOutsideWorkspace: truein plugin options. - If you are testing the dev endpoint manually, include the editor in the query string, for example:
/__click_to_source/open?file=src/App.tsx&line=10&column=3&editor=vscodeDevelopment
npm run verify
npm run test:smokenpm run test runs through tsx so the TypeScript tests are executed without Node's experimental strip-types mode.
npm run test:smoke validates packed-install flows for temporary Vite React, Vue, Svelte, and Angular apps.
Webpack and Rspack currently rely on unit coverage plus manual example validation.
The package is live on npm as click-to-source.
Repository docs:
CHANGELOG.md: released changesRELEASING.md: maintainer release processTODO.md: validation gaps and roadmap
License
MIT
