vite-plugin-qingkuai 1.0.17 → 1.0.18
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.cjs +67 -30
- package/dist/index.js +48 -30
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var vite = require('vite');
|
|
3
4
|
var nodePath = require('node:path');
|
|
4
5
|
var nodeCrypto = require('node:crypto');
|
|
5
6
|
var compiler = require('qingkuai/compiler');
|
|
@@ -8,14 +9,32 @@ var linesAndColumns = require('lines-and-columns');
|
|
|
8
9
|
var sourcemapCodec = require('@jridgewell/sourcemap-codec');
|
|
9
10
|
var postcss = require('postcss');
|
|
10
11
|
var selectorParser = require('postcss-selector-parser');
|
|
11
|
-
var vite = require('vite');
|
|
12
12
|
var sourceMapJs = require('source-map-js');
|
|
13
13
|
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
var n = Object.create(null);
|
|
16
|
+
if (e) {
|
|
17
|
+
Object.keys(e).forEach(function (k) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return e[k]; }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
|
|
32
|
+
|
|
14
33
|
const globalStyle = "\n" + compiler.util.formatSourceCode(
|
|
15
34
|
`
|
|
16
35
|
/* Injected by vite-plugin-qingkuai */
|
|
17
36
|
|
|
18
|
-
*[hidden]{
|
|
37
|
+
*[hidden] {
|
|
19
38
|
display: none !important;
|
|
20
39
|
}
|
|
21
40
|
`
|
|
@@ -133,18 +152,6 @@ function qingkuai() {
|
|
|
133
152
|
cssSourcemap = true;
|
|
134
153
|
sourcemap = config.build.sourcemap !== false;
|
|
135
154
|
}
|
|
136
|
-
const optimizeDeps = config.optimizeDeps;
|
|
137
|
-
if (!optimizeDeps) {
|
|
138
|
-
Object.assign(config, {
|
|
139
|
-
optimizeDeps: {
|
|
140
|
-
exclude: ["qingkuai"]
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
} else if (!optimizeDeps.exclude) {
|
|
144
|
-
optimizeDeps.exclude = ["qingkuai"];
|
|
145
|
-
} else {
|
|
146
|
-
optimizeDeps.exclude.push("qingkuai");
|
|
147
|
-
}
|
|
148
155
|
loadAllQingkuaiConfigurations(config.root);
|
|
149
156
|
},
|
|
150
157
|
transformIndexHtml(html) {
|
|
@@ -188,7 +195,7 @@ function qingkuai() {
|
|
|
188
195
|
break;
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
|
-
const preprocessRes = await
|
|
198
|
+
const preprocessRes = await vite__namespace.preprocessCSS(style.code, virtualFileName, {
|
|
192
199
|
...viteConfig,
|
|
193
200
|
css: {
|
|
194
201
|
...viteConfig.css,
|
|
@@ -288,7 +295,15 @@ function qingkuai() {
|
|
|
288
295
|
})
|
|
289
296
|
};
|
|
290
297
|
}
|
|
291
|
-
const
|
|
298
|
+
const inputMap = sourcemap ? {
|
|
299
|
+
version: 3,
|
|
300
|
+
sources: [id],
|
|
301
|
+
sourcesContent: [src],
|
|
302
|
+
mappings: compileRes.mappings
|
|
303
|
+
} : void 0;
|
|
304
|
+
const transformWithEsbuild = vite__namespace.transformWithEsbuild;
|
|
305
|
+
const transformWithOxc = vite__namespace.transformWithOxc;
|
|
306
|
+
const tsCompileRes = transformWithEsbuild ? await transformWithEsbuild(
|
|
292
307
|
compiledCode,
|
|
293
308
|
id,
|
|
294
309
|
{
|
|
@@ -296,20 +311,27 @@ function qingkuai() {
|
|
|
296
311
|
loader: "ts",
|
|
297
312
|
target: "esnext"
|
|
298
313
|
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
314
|
+
inputMap
|
|
315
|
+
) : transformWithOxc ? await transformWithOxc(
|
|
316
|
+
compiledCode,
|
|
317
|
+
id,
|
|
318
|
+
{
|
|
319
|
+
sourcemap,
|
|
320
|
+
target: "esnext"
|
|
321
|
+
},
|
|
322
|
+
inputMap
|
|
323
|
+
) : null;
|
|
324
|
+
if (!tsCompileRes) {
|
|
325
|
+
this.error("Current Vite runtime does not provide TypeScript transform APIs.");
|
|
326
|
+
}
|
|
306
327
|
if (!sourcemap) {
|
|
307
|
-
return
|
|
328
|
+
return tsCompileRes.code;
|
|
308
329
|
}
|
|
330
|
+
const transformedMap = typeof tsCompileRes.map === "string" ? JSON.parse(tsCompileRes.map) : tsCompileRes.map;
|
|
309
331
|
return {
|
|
310
|
-
code:
|
|
332
|
+
code: tsCompileRes.code,
|
|
311
333
|
map: Object.assign(baseMap, {
|
|
312
|
-
mappings:
|
|
334
|
+
mappings: transformedMap?.mappings || compileRes.mappings
|
|
313
335
|
})
|
|
314
336
|
};
|
|
315
337
|
} catch (err) {
|
|
@@ -343,10 +365,25 @@ function qingkuai() {
|
|
|
343
365
|
return config;
|
|
344
366
|
}
|
|
345
367
|
function createQingkuaiConfigurationWatcher(server) {
|
|
346
|
-
const watcher = server.watcher
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
368
|
+
const watcher = server.watcher;
|
|
369
|
+
const isQingkuaiConfig = (filePath) => {
|
|
370
|
+
return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
|
|
371
|
+
};
|
|
372
|
+
watcher.on("unlink", (filePath) => {
|
|
373
|
+
if (isQingkuaiConfig(filePath)) {
|
|
374
|
+
qingkuaiConfigurations.delete(nodePath.dirname(filePath));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
watcher.on("change", (filePath) => {
|
|
378
|
+
if (isQingkuaiConfig(filePath)) {
|
|
379
|
+
recordQingkuaiConfiguration(filePath);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
watcher.on("add", (filePath) => {
|
|
383
|
+
if (isQingkuaiConfig(filePath)) {
|
|
384
|
+
recordQingkuaiConfiguration(filePath);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
350
387
|
}
|
|
351
388
|
function loadAllQingkuaiConfigurations(workspaceDir) {
|
|
352
389
|
findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as vite from 'vite';
|
|
1
2
|
import nodePath from 'node:path';
|
|
2
3
|
import nodeCrypto from 'node:crypto';
|
|
3
4
|
import { util, compile } from 'qingkuai/compiler';
|
|
@@ -6,14 +7,13 @@ import { LinesAndColumns } from 'lines-and-columns';
|
|
|
6
7
|
import { decode, encode } from '@jridgewell/sourcemap-codec';
|
|
7
8
|
import postcss from 'postcss';
|
|
8
9
|
import selectorParser from 'postcss-selector-parser';
|
|
9
|
-
import { transformWithEsbuild, preprocessCSS } from 'vite';
|
|
10
10
|
import { SourceMapConsumer } from 'source-map-js';
|
|
11
11
|
|
|
12
12
|
const globalStyle = "\n" + util.formatSourceCode(
|
|
13
13
|
`
|
|
14
14
|
/* Injected by vite-plugin-qingkuai */
|
|
15
15
|
|
|
16
|
-
*[hidden]{
|
|
16
|
+
*[hidden] {
|
|
17
17
|
display: none !important;
|
|
18
18
|
}
|
|
19
19
|
`
|
|
@@ -131,18 +131,6 @@ function qingkuai() {
|
|
|
131
131
|
cssSourcemap = true;
|
|
132
132
|
sourcemap = config.build.sourcemap !== false;
|
|
133
133
|
}
|
|
134
|
-
const optimizeDeps = config.optimizeDeps;
|
|
135
|
-
if (!optimizeDeps) {
|
|
136
|
-
Object.assign(config, {
|
|
137
|
-
optimizeDeps: {
|
|
138
|
-
exclude: ["qingkuai"]
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
} else if (!optimizeDeps.exclude) {
|
|
142
|
-
optimizeDeps.exclude = ["qingkuai"];
|
|
143
|
-
} else {
|
|
144
|
-
optimizeDeps.exclude.push("qingkuai");
|
|
145
|
-
}
|
|
146
134
|
loadAllQingkuaiConfigurations(config.root);
|
|
147
135
|
},
|
|
148
136
|
transformIndexHtml(html) {
|
|
@@ -186,7 +174,7 @@ function qingkuai() {
|
|
|
186
174
|
break;
|
|
187
175
|
}
|
|
188
176
|
}
|
|
189
|
-
const preprocessRes = await preprocessCSS(style.code, virtualFileName, {
|
|
177
|
+
const preprocessRes = await vite.preprocessCSS(style.code, virtualFileName, {
|
|
190
178
|
...viteConfig,
|
|
191
179
|
css: {
|
|
192
180
|
...viteConfig.css,
|
|
@@ -286,7 +274,15 @@ function qingkuai() {
|
|
|
286
274
|
})
|
|
287
275
|
};
|
|
288
276
|
}
|
|
289
|
-
const
|
|
277
|
+
const inputMap = sourcemap ? {
|
|
278
|
+
version: 3,
|
|
279
|
+
sources: [id],
|
|
280
|
+
sourcesContent: [src],
|
|
281
|
+
mappings: compileRes.mappings
|
|
282
|
+
} : void 0;
|
|
283
|
+
const transformWithEsbuild = vite.transformWithEsbuild;
|
|
284
|
+
const transformWithOxc = vite.transformWithOxc;
|
|
285
|
+
const tsCompileRes = transformWithEsbuild ? await transformWithEsbuild(
|
|
290
286
|
compiledCode,
|
|
291
287
|
id,
|
|
292
288
|
{
|
|
@@ -294,20 +290,27 @@ function qingkuai() {
|
|
|
294
290
|
loader: "ts",
|
|
295
291
|
target: "esnext"
|
|
296
292
|
},
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
293
|
+
inputMap
|
|
294
|
+
) : transformWithOxc ? await transformWithOxc(
|
|
295
|
+
compiledCode,
|
|
296
|
+
id,
|
|
297
|
+
{
|
|
298
|
+
sourcemap,
|
|
299
|
+
target: "esnext"
|
|
300
|
+
},
|
|
301
|
+
inputMap
|
|
302
|
+
) : null;
|
|
303
|
+
if (!tsCompileRes) {
|
|
304
|
+
this.error("Current Vite runtime does not provide TypeScript transform APIs.");
|
|
305
|
+
}
|
|
304
306
|
if (!sourcemap) {
|
|
305
|
-
return
|
|
307
|
+
return tsCompileRes.code;
|
|
306
308
|
}
|
|
309
|
+
const transformedMap = typeof tsCompileRes.map === "string" ? JSON.parse(tsCompileRes.map) : tsCompileRes.map;
|
|
307
310
|
return {
|
|
308
|
-
code:
|
|
311
|
+
code: tsCompileRes.code,
|
|
309
312
|
map: Object.assign(baseMap, {
|
|
310
|
-
mappings:
|
|
313
|
+
mappings: transformedMap?.mappings || compileRes.mappings
|
|
311
314
|
})
|
|
312
315
|
};
|
|
313
316
|
} catch (err) {
|
|
@@ -341,10 +344,25 @@ function qingkuai() {
|
|
|
341
344
|
return config;
|
|
342
345
|
}
|
|
343
346
|
function createQingkuaiConfigurationWatcher(server) {
|
|
344
|
-
const watcher = server.watcher
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
347
|
+
const watcher = server.watcher;
|
|
348
|
+
const isQingkuaiConfig = (filePath) => {
|
|
349
|
+
return nodePath.basename(filePath) === ".qingkuairc" && !filePath.includes(`${nodePath.sep}node_modules${nodePath.sep}`);
|
|
350
|
+
};
|
|
351
|
+
watcher.on("unlink", (filePath) => {
|
|
352
|
+
if (isQingkuaiConfig(filePath)) {
|
|
353
|
+
qingkuaiConfigurations.delete(nodePath.dirname(filePath));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
watcher.on("change", (filePath) => {
|
|
357
|
+
if (isQingkuaiConfig(filePath)) {
|
|
358
|
+
recordQingkuaiConfiguration(filePath);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
watcher.on("add", (filePath) => {
|
|
362
|
+
if (isQingkuaiConfig(filePath)) {
|
|
363
|
+
recordQingkuaiConfiguration(filePath);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
348
366
|
}
|
|
349
367
|
function loadAllQingkuaiConfigurations(workspaceDir) {
|
|
350
368
|
findFilesByName(workspaceDir, ".qingkuairc", /* @__PURE__ */ new Set(["node_modules"])).forEach((fileName) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "vite-plugin-qingkuai",
|
|
3
3
|
"author": "mlgq",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.18",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"vite",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"rollup": "^4.38.0",
|
|
31
31
|
"rollup-plugin-dts": "^6.2.1",
|
|
32
32
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
33
|
-
"vite": "
|
|
33
|
+
"vite": "8.0.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"qingkuai": ">=1.0.50",
|
|
37
|
-
"vite": ">=6.2.4"
|
|
37
|
+
"vite": ">=6.2.4 <9"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@jridgewell/sourcemap-codec": "^1.5.0",
|