@md-plugins/vite-examples-plugin 0.1.0-rc.9 → 1.0.0
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/README.md +17 -5
- 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/README.md
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
# @md-plugins/vite-examples-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
|
|
4
|
+
[](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
|
|
5
|
+
[](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
|
|
6
|
+
[](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
|
|
7
|
+
|
|
8
|
+
<span class="badge-github-sponsors"><a href="https://github.com/sponsors/hawkeye64" title="Sponsor this project on GitHub"><img src="https://img.shields.io/badge/github-sponsors-ea4aaa.svg?logo=githubsponsors&logoColor=white" alt="GitHub Sponsors button" /></a></span>
|
|
9
|
+
<span class="badge-paypal"><a href="https://paypal.me/hawkeye64" title="Donate to this project using Paypal"><img src="https://img.shields.io/badge/paypal-donate-yellow.svg" alt="PayPal donate button" /></a></span>
|
|
10
|
+
|
|
11
|
+
[](https://chat.quasar.dev)
|
|
12
|
+
[](https://twitter.com/jgalbraith64)
|
|
13
|
+
|
|
14
|
+
A Vite plugin for documentation examples. It loads Vue example components and their raw source so docs pages can render a live demo, show the source code, and export the same example to CodePen-style sandboxes.
|
|
4
15
|
|
|
5
16
|
## Features
|
|
6
17
|
|
|
7
|
-
-
|
|
8
|
-
- Generates
|
|
9
|
-
-
|
|
10
|
-
-
|
|
18
|
+
- Loads Vue example files dynamically during development.
|
|
19
|
+
- Generates stable example imports for production builds.
|
|
20
|
+
- Provides both compiled components and raw source strings.
|
|
21
|
+
- Supports Q-Press `MarkdownExample` usage and direct Vue/Vite documentation sites.
|
|
22
|
+
- Includes manual chunk helpers for keeping example bundles organized.
|
|
11
23
|
|
|
12
24
|
## Installation
|
|
13
25
|
|
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": "
|
|
3
|
+
"version": "1.0.0",
|
|
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.
|
|
44
|
+
"vite": "^8.1.3"
|
|
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
|
}
|