@md-plugins/vite-examples-plugin 0.1.0-rc.18 → 0.1.0-rc.19
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.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.mjs +36 -48
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a Vite plugin for handling Markdown examples.
|
|
5
4
|
*
|
|
@@ -23,11 +22,13 @@ import { Plugin } from 'vite';
|
|
|
23
22
|
/**
|
|
24
23
|
* Creates the md-plugins examples plugin and configures its example source path.
|
|
25
24
|
*/
|
|
26
|
-
declare function viteExamplesPlugin({
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
declare function viteExamplesPlugin({
|
|
26
|
+
isProd,
|
|
27
|
+
path
|
|
28
|
+
}: {
|
|
29
|
+
isProd: boolean;
|
|
30
|
+
path: string;
|
|
29
31
|
}): Plugin;
|
|
30
|
-
|
|
31
32
|
/**
|
|
32
33
|
* A function to determine the manual chunk name for a given module ID.
|
|
33
34
|
*
|
|
@@ -38,5 +39,4 @@ declare function viteExamplesPlugin({ isProd, path }: {
|
|
|
38
39
|
* Places Quasar docs examples and related vendors into stable Vite manual chunks.
|
|
39
40
|
*/
|
|
40
41
|
declare function viteManualChunks(id: string): string | undefined;
|
|
41
|
-
|
|
42
|
-
export { viteExamplesPlugin, viteManualChunks };
|
|
42
|
+
export { viteExamplesPlugin, viteManualChunks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
3
2
|
/**
|
|
4
3
|
* Creates a Vite plugin for handling Markdown examples.
|
|
5
4
|
*
|
|
@@ -23,11 +22,13 @@ import { Plugin } from 'vite';
|
|
|
23
22
|
/**
|
|
24
23
|
* Creates the md-plugins examples plugin and configures its example source path.
|
|
25
24
|
*/
|
|
26
|
-
declare function viteExamplesPlugin({
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
declare function viteExamplesPlugin({
|
|
26
|
+
isProd,
|
|
27
|
+
path
|
|
28
|
+
}: {
|
|
29
|
+
isProd: boolean;
|
|
30
|
+
path: string;
|
|
29
31
|
}): Plugin;
|
|
30
|
-
|
|
31
32
|
/**
|
|
32
33
|
* A function to determine the manual chunk name for a given module ID.
|
|
33
34
|
*
|
|
@@ -38,5 +39,4 @@ declare function viteExamplesPlugin({ isProd, path }: {
|
|
|
38
39
|
* Places Quasar docs examples and related vendors into stable Vite manual chunks.
|
|
39
40
|
*/
|
|
40
41
|
declare function viteManualChunks(id: string): string | undefined;
|
|
41
|
-
|
|
42
|
-
export { viteExamplesPlugin, viteManualChunks };
|
|
42
|
+
export { viteExamplesPlugin, viteManualChunks };
|
package/dist/index.mjs
CHANGED
|
@@ -1,66 +1,54 @@
|
|
|
1
|
-
import { join } from
|
|
2
|
-
import { globSync } from
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { globSync } from "tinyglobby";
|
|
3
3
|
|
|
4
4
|
const moduleIdRE = /^examples:/;
|
|
5
5
|
const resolvedIdPrefix = "\0examples:";
|
|
6
6
|
let targetFolder = "";
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
function devLoad(id) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return void 0;
|
|
10
|
+
if (id.startsWith(resolvedIdPrefix)) {
|
|
11
|
+
const query = `'/src/examples/${id.substring(id.indexOf(":") + 1)}/*.vue'`;
|
|
12
|
+
return `export const code = import.meta.glob(${query})\nexport const source = import.meta.glob(${query}, { query: '?raw', import: 'default' })`;
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
|
|
15
17
|
function prodLoad(id) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(entry) => `import ${entry} from '@/examples/${exampleId}/${entry}.vue'
|
|
22
|
-
import Raw${entry} from '@/examples/${exampleId}/${entry}.vue?raw'`
|
|
23
|
-
).join("\n");
|
|
24
|
-
const exportStatements = importList.map((entry) => `${entry},Raw${entry}`).join(",");
|
|
25
|
-
return importStatements + `
|
|
26
|
-
export {${exportStatements}}`;
|
|
27
|
-
}
|
|
28
|
-
return void 0;
|
|
18
|
+
if (id.startsWith(resolvedIdPrefix)) {
|
|
19
|
+
const exampleId = id.substring(id.indexOf(":") + 1);
|
|
20
|
+
const importList = globSync("*.vue", { cwd: join(targetFolder, exampleId) }).map((entry) => entry.substring(0, entry.length - 4));
|
|
21
|
+
return importList.map((entry) => `import ${entry} from '@/examples/${exampleId}/${entry}.vue'\nimport Raw${entry} from '@/examples/${exampleId}/${entry}.vue?raw'`).join("\n") + `\nexport {${importList.map((entry) => `${entry},Raw${entry}`).join(",")}}`;
|
|
22
|
+
}
|
|
29
23
|
}
|
|
24
|
+
|
|
25
|
+
|
|
30
26
|
function vitePlugin(isProd) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return "\0" + id;
|
|
41
|
-
}
|
|
42
|
-
return void 0;
|
|
43
|
-
},
|
|
44
|
-
load: isProd ? prodLoad : devLoad
|
|
45
|
-
};
|
|
27
|
+
if (!targetFolder) throw new Error("targetFolder is not defined");
|
|
28
|
+
return {
|
|
29
|
+
name: "markdown-examples",
|
|
30
|
+
enforce: "pre",
|
|
31
|
+
resolveId(id) {
|
|
32
|
+
if (moduleIdRE.test(id)) return "\0" + id;
|
|
33
|
+
},
|
|
34
|
+
load: isProd ? prodLoad : devLoad
|
|
35
|
+
};
|
|
46
36
|
}
|
|
37
|
+
|
|
38
|
+
|
|
47
39
|
function viteExamplesPlugin({ isProd, path }) {
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
targetFolder = path;
|
|
41
|
+
return vitePlugin(isProd);
|
|
50
42
|
}
|
|
51
43
|
|
|
52
44
|
const vendorRE = /node_modules[\\/](vue|@vue|quasar|vue-router)[\\/](.*)\.(m?js|css|sass)$/;
|
|
53
45
|
const exampleRE = /examples:([a-zA-Z0-9]+)$|src[\\/]examples[\\/]([a-zA-Z0-9-]+)/;
|
|
46
|
+
|
|
47
|
+
|
|
54
48
|
function viteManualChunks(id) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const examplesMatch = exampleRE.exec(id);
|
|
59
|
-
if (examplesMatch !== null) {
|
|
60
|
-
const name = examplesMatch[1] || examplesMatch[2];
|
|
61
|
-
return `e.${name}`;
|
|
62
|
-
}
|
|
63
|
-
return void 0;
|
|
49
|
+
if (vendorRE.test(id)) return "vendor";
|
|
50
|
+
const examplesMatch = exampleRE.exec(id);
|
|
51
|
+
if (examplesMatch !== null) return `e.${examplesMatch[1] || examplesMatch[2]}`;
|
|
64
52
|
}
|
|
65
53
|
|
|
66
|
-
export { viteExamplesPlugin, viteManualChunks };
|
|
54
|
+
export { viteExamplesPlugin, viteManualChunks };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/vite-examples-plugin",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.19",
|
|
4
4
|
"description": "A Vite plugin for @md-plugins for handling imported examples in markdown files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"tinyglobby": "^0.2.17"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"vite": "^8.1.
|
|
44
|
+
"vite": "^8.1.1"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
|
-
"build": "
|
|
47
|
+
"build": "obuild && node ../../scripts/ensure-obuild-types.mjs",
|
|
48
48
|
"clean": "rm -rf dist/ node_modules/"
|
|
49
49
|
}
|
|
50
50
|
}
|