vite-plugin-enter-dev 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +215 -1
- package/package.json +11 -10
package/dist/index.js
CHANGED
|
@@ -3,10 +3,189 @@ import react from '@vitejs/plugin-react';
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
|
|
5
5
|
// src/sourceInfoInjectPlugin.ts
|
|
6
|
+
var threeFiberElems = /* @__PURE__ */ new Set([
|
|
7
|
+
"object3D",
|
|
8
|
+
"audioListener",
|
|
9
|
+
"positionalAudio",
|
|
10
|
+
"mesh",
|
|
11
|
+
"batchedMesh",
|
|
12
|
+
"instancedMesh",
|
|
13
|
+
"scene",
|
|
14
|
+
"sprite",
|
|
15
|
+
"lOD",
|
|
16
|
+
"skinnedMesh",
|
|
17
|
+
"skeleton",
|
|
18
|
+
"bone",
|
|
19
|
+
"lineSegments",
|
|
20
|
+
"lineLoop",
|
|
21
|
+
"points",
|
|
22
|
+
"group",
|
|
23
|
+
"camera",
|
|
24
|
+
"perspectiveCamera",
|
|
25
|
+
"orthographicCamera",
|
|
26
|
+
"cubeCamera",
|
|
27
|
+
"arrayCamera",
|
|
28
|
+
"instancedBufferGeometry",
|
|
29
|
+
"bufferGeometry",
|
|
30
|
+
"boxBufferGeometry",
|
|
31
|
+
"circleBufferGeometry",
|
|
32
|
+
"coneBufferGeometry",
|
|
33
|
+
"cylinderBufferGeometry",
|
|
34
|
+
"dodecahedronBufferGeometry",
|
|
35
|
+
"extrudeBufferGeometry",
|
|
36
|
+
"icosahedronBufferGeometry",
|
|
37
|
+
"latheBufferGeometry",
|
|
38
|
+
"octahedronBufferGeometry",
|
|
39
|
+
"planeBufferGeometry",
|
|
40
|
+
"polyhedronBufferGeometry",
|
|
41
|
+
"ringBufferGeometry",
|
|
42
|
+
"shapeBufferGeometry",
|
|
43
|
+
"sphereBufferGeometry",
|
|
44
|
+
"tetrahedronBufferGeometry",
|
|
45
|
+
"torusBufferGeometry",
|
|
46
|
+
"torusKnotBufferGeometry",
|
|
47
|
+
"tubeBufferGeometry",
|
|
48
|
+
"wireframeGeometry",
|
|
49
|
+
"tetrahedronGeometry",
|
|
50
|
+
"octahedronGeometry",
|
|
51
|
+
"icosahedronGeometry",
|
|
52
|
+
"dodecahedronGeometry",
|
|
53
|
+
"polyhedronGeometry",
|
|
54
|
+
"tubeGeometry",
|
|
55
|
+
"torusKnotGeometry",
|
|
56
|
+
"torusGeometry",
|
|
57
|
+
"sphereGeometry",
|
|
58
|
+
"ringGeometry",
|
|
59
|
+
"planeGeometry",
|
|
60
|
+
"latheGeometry",
|
|
61
|
+
"shapeGeometry",
|
|
62
|
+
"extrudeGeometry",
|
|
63
|
+
"edgesGeometry",
|
|
64
|
+
"coneGeometry",
|
|
65
|
+
"cylinderGeometry",
|
|
66
|
+
"circleGeometry",
|
|
67
|
+
"boxGeometry",
|
|
68
|
+
"capsuleGeometry",
|
|
69
|
+
"material",
|
|
70
|
+
"shadowMaterial",
|
|
71
|
+
"spriteMaterial",
|
|
72
|
+
"rawShaderMaterial",
|
|
73
|
+
"shaderMaterial",
|
|
74
|
+
"pointsMaterial",
|
|
75
|
+
"meshPhysicalMaterial",
|
|
76
|
+
"meshStandardMaterial",
|
|
77
|
+
"meshPhongMaterial",
|
|
78
|
+
"meshToonMaterial",
|
|
79
|
+
"meshNormalMaterial",
|
|
80
|
+
"meshLambertMaterial",
|
|
81
|
+
"meshDepthMaterial",
|
|
82
|
+
"meshDistanceMaterial",
|
|
83
|
+
"meshBasicMaterial",
|
|
84
|
+
"meshMatcapMaterial",
|
|
85
|
+
"lineDashedMaterial",
|
|
86
|
+
"lineBasicMaterial",
|
|
87
|
+
"primitive",
|
|
88
|
+
"light",
|
|
89
|
+
"spotLightShadow",
|
|
90
|
+
"spotLight",
|
|
91
|
+
"pointLight",
|
|
92
|
+
"rectAreaLight",
|
|
93
|
+
"hemisphereLight",
|
|
94
|
+
"directionalLightShadow",
|
|
95
|
+
"directionalLight",
|
|
96
|
+
"ambientLight",
|
|
97
|
+
"lightShadow",
|
|
98
|
+
"ambientLightProbe",
|
|
99
|
+
"hemisphereLightProbe",
|
|
100
|
+
"lightProbe",
|
|
101
|
+
"spotLightHelper",
|
|
102
|
+
"skeletonHelper",
|
|
103
|
+
"pointLightHelper",
|
|
104
|
+
"hemisphereLightHelper",
|
|
105
|
+
"gridHelper",
|
|
106
|
+
"polarGridHelper",
|
|
107
|
+
"directionalLightHelper",
|
|
108
|
+
"cameraHelper",
|
|
109
|
+
"boxHelper",
|
|
110
|
+
"box3Helper",
|
|
111
|
+
"planeHelper",
|
|
112
|
+
"arrowHelper",
|
|
113
|
+
"axesHelper",
|
|
114
|
+
"texture",
|
|
115
|
+
"videoTexture",
|
|
116
|
+
"dataTexture",
|
|
117
|
+
"dataTexture3D",
|
|
118
|
+
"compressedTexture",
|
|
119
|
+
"cubeTexture",
|
|
120
|
+
"canvasTexture",
|
|
121
|
+
"depthTexture",
|
|
122
|
+
"raycaster",
|
|
123
|
+
"vector2",
|
|
124
|
+
"vector3",
|
|
125
|
+
"vector4",
|
|
126
|
+
"euler",
|
|
127
|
+
"matrix3",
|
|
128
|
+
"matrix4",
|
|
129
|
+
"quaternion",
|
|
130
|
+
"bufferAttribute",
|
|
131
|
+
"float16BufferAttribute",
|
|
132
|
+
"float32BufferAttribute",
|
|
133
|
+
"float64BufferAttribute",
|
|
134
|
+
"int8BufferAttribute",
|
|
135
|
+
"int16BufferAttribute",
|
|
136
|
+
"int32BufferAttribute",
|
|
137
|
+
"uint8BufferAttribute",
|
|
138
|
+
"uint16BufferAttribute",
|
|
139
|
+
"uint32BufferAttribute",
|
|
140
|
+
"instancedBufferAttribute",
|
|
141
|
+
"color",
|
|
142
|
+
"fog",
|
|
143
|
+
"fogExp2",
|
|
144
|
+
"shape",
|
|
145
|
+
"colorShiftMaterial"
|
|
146
|
+
]);
|
|
147
|
+
function shouldTagElement(elementName, threeDreiImportedElements, threeDreiNamespaces) {
|
|
148
|
+
if (threeFiberElems.has(elementName)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (threeDreiImportedElements.has(elementName)) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (elementName.includes(".")) {
|
|
155
|
+
const namespace = elementName.split(".")[0] || "";
|
|
156
|
+
if (threeDreiNamespaces.has(namespace)) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
6
162
|
function injectSourcePlugin({ types: t }) {
|
|
7
163
|
return {
|
|
8
164
|
name: "inject-source-location-enhanced",
|
|
9
165
|
visitor: {
|
|
166
|
+
Program: {
|
|
167
|
+
enter(path, state) {
|
|
168
|
+
state.threeImportedElements = /* @__PURE__ */ new Set();
|
|
169
|
+
state.threeNamespaces = /* @__PURE__ */ new Set();
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
ImportDeclaration(path, state) {
|
|
173
|
+
const threeLibraries = [
|
|
174
|
+
"@react-three/fiber",
|
|
175
|
+
"@react-three/drei",
|
|
176
|
+
"@react-three/postprocessing",
|
|
177
|
+
"three"
|
|
178
|
+
];
|
|
179
|
+
if (threeLibraries.includes(path.node.source.value)) {
|
|
180
|
+
path.node.specifiers.forEach((spec) => {
|
|
181
|
+
if (spec.type === "ImportSpecifier") {
|
|
182
|
+
state.threeImportedElements.add(spec.local.name);
|
|
183
|
+
} else if (spec.type === "ImportNamespaceSpecifier") {
|
|
184
|
+
state.threeNamespaces.add(spec.local.name);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
},
|
|
10
189
|
JSXElement(path, state) {
|
|
11
190
|
const { node } = path;
|
|
12
191
|
const filename = state.filename || state.file.opts.filename || "unknown";
|
|
@@ -16,6 +195,9 @@ function injectSourcePlugin({ types: t }) {
|
|
|
16
195
|
const relativePath = filename.replace(/^.*\/src\//, "src/").replace(/\\/g, "/");
|
|
17
196
|
const sourceLocation = `${relativePath}:${start.line}:${start.column + 1}`;
|
|
18
197
|
const elementType = getElementType(node.openingElement.name);
|
|
198
|
+
if (!shouldTagElement(elementType, state.threeImportedElements || /* @__PURE__ */ new Set(), state.threeNamespaces || /* @__PURE__ */ new Set())) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
19
201
|
const elementInfo = {
|
|
20
202
|
fileName: relativePath,
|
|
21
203
|
lineNumber: start.line,
|
|
@@ -251,7 +433,39 @@ function enterDevPlugin(options = {}) {
|
|
|
251
433
|
return html;
|
|
252
434
|
}
|
|
253
435
|
};
|
|
254
|
-
|
|
436
|
+
const sandboxServerPlugin = {
|
|
437
|
+
name: "enter-dev-sandbox-server",
|
|
438
|
+
config(_, { command }) {
|
|
439
|
+
if (command !== "serve") return;
|
|
440
|
+
const isSandbox = process.cwd().startsWith("/workspace");
|
|
441
|
+
if (!isSandbox) return;
|
|
442
|
+
const port = process.env.ENTER_DEV_PORT ? parseInt(process.env.ENTER_DEV_PORT, 10) : void 0;
|
|
443
|
+
const basePath = process.env.ENTER_BASE_PATH || void 0;
|
|
444
|
+
return {
|
|
445
|
+
...basePath && { base: basePath },
|
|
446
|
+
server: {
|
|
447
|
+
...port && { port },
|
|
448
|
+
allowedHosts: true,
|
|
449
|
+
watch: { usePolling: true, interval: 500 }
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
const routerBasePlugin = {
|
|
455
|
+
name: "enter-dev-router-base",
|
|
456
|
+
enforce: "pre",
|
|
457
|
+
transform(code, id) {
|
|
458
|
+
if (!process.env.ENTER_BASE_PATH) return;
|
|
459
|
+
if (!id.match(/\.[jt]sx?$/)) return;
|
|
460
|
+
if (!code.includes("createBrowserRouter")) return;
|
|
461
|
+
if (code.includes("basename")) return;
|
|
462
|
+
return code.replace(
|
|
463
|
+
/createBrowserRouter\(([^,)]+)\)/g,
|
|
464
|
+
"createBrowserRouter($1, { basename: import.meta.env.BASE_URL })"
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
return [...reactPlugin, htmlInjectPlugin, sandboxServerPlugin, routerBasePlugin];
|
|
255
469
|
}
|
|
256
470
|
function enterProdPlugin(options = {}) {
|
|
257
471
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-enter-dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "A Vite plugin for development enhancements",
|
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup",
|
|
21
|
+
"dev": "tsup --watch",
|
|
22
|
+
"lint": "eslint . --max-warnings 0"
|
|
23
|
+
},
|
|
19
24
|
"keywords": [
|
|
20
25
|
"vite",
|
|
21
26
|
"vite-plugin",
|
|
@@ -25,23 +30,19 @@
|
|
|
25
30
|
],
|
|
26
31
|
"author": "",
|
|
27
32
|
"license": "MIT",
|
|
33
|
+
"packageManager": "pnpm@10.15.0",
|
|
28
34
|
"devDependencies": {
|
|
29
35
|
"@types/node": "^20.19.9",
|
|
36
|
+
"@workspace/eslint-config": "workspace:*",
|
|
37
|
+
"@workspace/typescript-config": "workspace:*",
|
|
30
38
|
"tsup": "^8.5.1",
|
|
31
39
|
"typescript": "^5.9.2",
|
|
32
|
-
"vite": "^6.0.0"
|
|
33
|
-
"@workspace/typescript-config": "0.0.0",
|
|
34
|
-
"@workspace/eslint-config": "0.0.0"
|
|
40
|
+
"vite": "^6.0.0"
|
|
35
41
|
},
|
|
36
42
|
"peerDependencies": {
|
|
37
43
|
"vite": "^5.0.0 || ^6.0.0"
|
|
38
44
|
},
|
|
39
45
|
"dependencies": {
|
|
40
46
|
"@vitejs/plugin-react": "^5.1.1"
|
|
41
|
-
},
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "tsup",
|
|
44
|
-
"dev": "tsup --watch",
|
|
45
|
-
"lint": "eslint . --max-warnings 0"
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|