File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## Unreleased
4
+
5
+ - Add support for Vite base path
6
+
3
7
## 4.0.0
4
8
5
9
- Align with Vite 7: ESM only, node 20.19+
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ style.innerHTML = `[data-click-to-component-target] {
37
37
document . head . appendChild ( style ) ;
38
38
39
39
const root = "__ROOT__" ;
40
+ const base = "__BASE__" ;
40
41
let currentTarget : HTMLElement | undefined ;
41
42
let hasMenu = false ;
42
43
const menuElement = document . createElement ( "div" ) ;
@@ -123,7 +124,9 @@ window.addEventListener("contextmenu", (event) => {
123
124
spanR . textContent = layer . path . replace ( `${ root } /` , "" ) ;
124
125
item . appendChild ( spanR ) ;
125
126
item . addEventListener ( "click" , ( ) => {
126
- void fetch ( `/__open-in-editor?file=${ encodeURIComponent ( layer . path ) } ` ) ;
127
+ void fetch (
128
+ `${ base } __open-in-editor?file=${ encodeURIComponent ( layer . path ) } ` ,
129
+ ) ;
127
130
cleanUp ( ) ;
128
131
} ) ;
129
132
menuElement . appendChild ( item ) ;
Original file line number Diff line number Diff line change @@ -3,21 +3,22 @@ import { join } from "node:path";
3
3
import type { PluginOption } from "vite" ;
4
4
5
5
let root = "" ;
6
+ let base = "" ;
6
7
7
8
export const reactClickToComponent = ( ) : PluginOption => ( {
8
9
name : "react-click-to-component" ,
9
10
apply : "serve" ,
10
11
configResolved ( config ) {
11
12
root = config . root ;
13
+ base = config . base ;
12
14
} ,
13
15
transformIndexHtml : ( ) => [
14
16
{
15
17
tag : "script" ,
16
18
attrs : { type : "module" } ,
17
- children : readFileSync (
18
- join ( import . meta. dirname , "client.js" ) ,
19
- "utf-8" ,
20
- ) . replace ( "__ROOT__" , root ) ,
19
+ children : readFileSync ( join ( import . meta. dirname , "client.js" ) , "utf-8" )
20
+ . replace ( "__ROOT__" , root )
21
+ . replace ( "__BASE__" , base ) ,
21
22
} ,
22
23
] ,
23
24
transform ( code , id ) {
You can’t perform that action at this time.
0 commit comments