@tsrx/vite-plugin-vue 0.0.92 → 0.0.94
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/package.json +3 -3
- package/src/index.js +35 -22
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Vite plugin for @tsrx/vue (.tsrx modules)",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.94",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@tsrx/core": "0.
|
|
24
|
-
"@tsrx/vue": "0.2.
|
|
23
|
+
"@tsrx/core": "0.3.1",
|
|
24
|
+
"@tsrx/vue": "0.2.6"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vite": "*",
|
package/src/index.js
CHANGED
|
@@ -9,11 +9,15 @@ import { compile } from '@tsrx/vue';
|
|
|
9
9
|
import { mergePlatformDefinitions, validatePlatform } from '@tsrx/core';
|
|
10
10
|
import { resolveBuildPlatform } from '@tsrx/core/config';
|
|
11
11
|
import { createDepScanLoadPlugin } from '@tsrx/core/vite/dep-scan';
|
|
12
|
+
import { createWorkerEntryMiddleware, stripWorkerEntryQuery } from '@tsrx/core/vite/worker';
|
|
12
13
|
import vueJsxVaporModule from 'vue-jsx-vapor/vite';
|
|
13
14
|
import { createVaporInteropPlugin } from './interop.js';
|
|
14
15
|
|
|
15
16
|
const DEFAULT_TSRX_PATTERN = /\.tsrx$/;
|
|
16
17
|
const VIRTUAL_TSX_SUFFIX = '.tsx';
|
|
18
|
+
// CSS ids stay the component path plus this query, with no `\0` prefix, so
|
|
19
|
+
// Vite resolves relative `@import` and `url()` references in the extracted
|
|
20
|
+
// CSS from the component's directory.
|
|
17
21
|
const CSS_QUERY = '?tsrx-vue-css&lang.css';
|
|
18
22
|
const DEFAULT_VAPOR_OPTIONS = {
|
|
19
23
|
macros: true,
|
|
@@ -179,48 +183,56 @@ function create_tsrx_vue_plugin(options) {
|
|
|
179
183
|
rootDir = config.root;
|
|
180
184
|
},
|
|
181
185
|
|
|
186
|
+
configureServer(server) {
|
|
187
|
+
server.middlewares.use(createWorkerEntryMiddleware(isTsrxSource));
|
|
188
|
+
},
|
|
189
|
+
|
|
182
190
|
async resolveId(source, importer, options) {
|
|
183
|
-
if (source.includes(CSS_QUERY))
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
if (source.includes(CSS_QUERY)) return source;
|
|
192
|
+
|
|
193
|
+
// A dev worker entry arrives as `<path>?worker_file&type=<type>`.
|
|
194
|
+
// Resolve the path, then keep the query on the virtual id: Vite's
|
|
195
|
+
// worker plugin reads it back to set the entry up as a worker.
|
|
196
|
+
const path = stripWorkerEntryQuery(source);
|
|
197
|
+
const workerQuery = source.slice(path.length);
|
|
187
198
|
|
|
188
|
-
if (isVirtual(
|
|
199
|
+
if (isVirtual(path)) {
|
|
189
200
|
return isAbsolute(source) ? source : pathResolve(rootDir, source.replace(/^\/+/, ''));
|
|
190
201
|
}
|
|
191
202
|
|
|
192
|
-
if (isTsrxSource(
|
|
193
|
-
const resolved = await this.resolve(
|
|
203
|
+
if (isTsrxSource(path)) {
|
|
204
|
+
const resolved = await this.resolve(path, importer, { ...options, skipSelf: true });
|
|
194
205
|
if (resolved && !isVirtual(resolved.id)) {
|
|
195
206
|
const resolvedId = isAbsolute(resolved.id)
|
|
196
207
|
? resolved.id
|
|
197
208
|
: pathResolve(rootDir, resolved.id.replace(/^\/+/, ''));
|
|
198
|
-
return { ...resolved, id: resolvedId + VIRTUAL_TSX_SUFFIX };
|
|
209
|
+
return { ...resolved, id: resolvedId + VIRTUAL_TSX_SUFFIX + workerQuery };
|
|
199
210
|
}
|
|
200
|
-
if (resolved) return resolved;
|
|
211
|
+
if (resolved) return { ...resolved, id: resolved.id + workerQuery };
|
|
201
212
|
// Re-anchor the fallback virtual id to an absolute path so
|
|
202
213
|
// downstream import resolution walks `node_modules` from the
|
|
203
214
|
// real file's location rather than from workspace root —
|
|
204
215
|
// otherwise package deps declared inside
|
|
205
216
|
// `packages/<pkg>/node_modules` are invisible to vite.
|
|
206
|
-
const absoluteSource = isAbsolute(
|
|
207
|
-
?
|
|
208
|
-
: pathResolve(rootDir,
|
|
209
|
-
return absoluteSource + VIRTUAL_TSX_SUFFIX;
|
|
217
|
+
const absoluteSource = isAbsolute(path)
|
|
218
|
+
? path
|
|
219
|
+
: pathResolve(rootDir, path.replace(/^\/+/, ''));
|
|
220
|
+
return absoluteSource + VIRTUAL_TSX_SUFFIX + workerQuery;
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
return null;
|
|
213
224
|
},
|
|
214
225
|
|
|
215
226
|
async load(id) {
|
|
216
|
-
if (id.
|
|
217
|
-
const key = id.
|
|
227
|
+
if (id.includes(CSS_QUERY)) {
|
|
228
|
+
const key = id.split('?')[0];
|
|
218
229
|
return cssCache.get(key) ?? '';
|
|
219
230
|
}
|
|
220
231
|
|
|
221
|
-
|
|
232
|
+
const path = stripWorkerEntryQuery(id);
|
|
233
|
+
if (!isVirtual(path)) return null;
|
|
222
234
|
|
|
223
|
-
const realPath = toRealPath(
|
|
235
|
+
const realPath = toRealPath(path);
|
|
224
236
|
const source = await readFile(realPath, 'utf-8');
|
|
225
237
|
let { code, css, map } = compile(source, realPath, compile_options);
|
|
226
238
|
|
|
@@ -239,13 +251,14 @@ function create_tsrx_vue_plugin(options) {
|
|
|
239
251
|
handleHotUpdate(ctx) {
|
|
240
252
|
if (!isTsrxSource(ctx.file)) return;
|
|
241
253
|
|
|
254
|
+
// Look the virtual modules up by file to include a worker entry's
|
|
255
|
+
// query-suffixed id.
|
|
242
256
|
const virtualId = ctx.file + VIRTUAL_TSX_SUFFIX;
|
|
243
|
-
const cssVirtualId =
|
|
244
|
-
const extra = [];
|
|
245
|
-
const mod = ctx.server.moduleGraph.getModuleById(virtualId);
|
|
246
|
-
if (mod) extra.push(mod);
|
|
257
|
+
const cssVirtualId = ctx.file + CSS_QUERY;
|
|
258
|
+
const extra = [...(ctx.server.moduleGraph.getModulesByFile(virtualId) ?? [])];
|
|
247
259
|
const cssMod = ctx.server.moduleGraph.getModuleById(cssVirtualId);
|
|
248
|
-
|
|
260
|
+
// Vite usually lists the CSS module already, under the component's file.
|
|
261
|
+
if (cssMod && !ctx.modules.includes(cssMod)) extra.push(cssMod);
|
|
249
262
|
if (extra.length > 0) return [...extra, ...ctx.modules];
|
|
250
263
|
return ctx.modules;
|
|
251
264
|
},
|