@md-plugins/vite-examples-plugin 0.1.0-rc.9 → 1.1.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 CHANGED
@@ -1,13 +1,25 @@
1
1
  # @md-plugins/vite-examples-plugin
2
2
 
3
- A Vite plugin that facilitates handling Vue example files in both development and production modes. The plugin allows you to load and transform example components and their raw source code for usage in your application.
3
+ [![npm version](https://img.shields.io/npm/v/@md-plugins/vite-examples-plugin?label=%40md-plugins%2Fvite-examples-plugin)](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
4
+ [![npm downloads](https://img.shields.io/npm/dt/@md-plugins/vite-examples-plugin)](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
5
+ [![npm monthly downloads](https://img.shields.io/npm/dm/@md-plugins/vite-examples-plugin)](https://www.npmjs.com/package/@md-plugins/vite-examples-plugin)
6
+ [![license](https://img.shields.io/npm/l/@md-plugins/vite-examples-plugin)](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
+ [![Discord](https://img.shields.io/badge/discord-join%20server-738ADB?style=for-the-badge&logo=discord&logoColor=738ADB)](https://chat.quasar.dev)
12
+ [![X](https://img.shields.io/badge/follow-@jgalbraith64-1DA1F2?style=for-the-badge&logo=x&logoColor=1DA1F2)](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
- - Supports loading Vue example files dynamically during development.
8
- - Generates import and export statements for Vue example files in production.
9
- - Easily handles raw and compiled component imports.
10
- - Enables seamless integration of example files into your project.
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 'vite';
2
-
1
+ import { Plugin } from "vite";
3
2
  /**
4
3
  * Creates a Vite plugin for handling Markdown examples.
5
4
  *
@@ -24,10 +23,9 @@ import { Plugin } from 'vite';
24
23
  * Creates the md-plugins examples plugin and configures its example source path.
25
24
  */
26
25
  declare function viteExamplesPlugin({ isProd, path }: {
27
- isProd: boolean;
28
- path: string;
26
+ isProd: boolean;
27
+ path: string;
29
28
  }): Plugin;
30
-
31
29
  /**
32
30
  * A function to determine the manual chunk name for a given module ID.
33
31
  *
@@ -38,5 +36,4 @@ declare function viteExamplesPlugin({ isProd, path }: {
38
36
  * Places Quasar docs examples and related vendors into stable Vite manual chunks.
39
37
  */
40
38
  declare function viteManualChunks(id: string): string | undefined;
41
-
42
- export { viteExamplesPlugin, viteManualChunks };
39
+ export { viteExamplesPlugin, viteManualChunks };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Plugin } from 'vite';
2
-
1
+ import { Plugin } from "vite";
3
2
  /**
4
3
  * Creates a Vite plugin for handling Markdown examples.
5
4
  *
@@ -24,10 +23,9 @@ import { Plugin } from 'vite';
24
23
  * Creates the md-plugins examples plugin and configures its example source path.
25
24
  */
26
25
  declare function viteExamplesPlugin({ isProd, path }: {
27
- isProd: boolean;
28
- path: string;
26
+ isProd: boolean;
27
+ path: string;
29
28
  }): Plugin;
30
-
31
29
  /**
32
30
  * A function to determine the manual chunk name for a given module ID.
33
31
  *
@@ -38,5 +36,4 @@ declare function viteExamplesPlugin({ isProd, path }: {
38
36
  * Places Quasar docs examples and related vendors into stable Vite manual chunks.
39
37
  */
40
38
  declare function viteManualChunks(id: string): string | undefined;
41
-
42
- export { viteExamplesPlugin, viteManualChunks };
39
+ export { viteExamplesPlugin, viteManualChunks };
package/dist/index.mjs CHANGED
@@ -1,66 +1,54 @@
1
- import { join } from 'node:path';
2
- import { globSync } from 'tinyglobby';
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
- if (id.startsWith(resolvedIdPrefix)) {
9
- const query = `'/src/examples/${id.substring(id.indexOf(":") + 1)}/*.vue'`;
10
- return `export const code = import.meta.glob(${query})
11
- export const source = import.meta.glob(${query}, { query: '?raw', import: 'default' })`;
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
- if (id.startsWith(resolvedIdPrefix)) {
17
- const exampleId = id.substring(id.indexOf(":") + 1);
18
- const files = globSync("*.vue", { cwd: join(targetFolder, exampleId) });
19
- const importList = files.map((entry) => entry.substring(0, entry.length - 4));
20
- const importStatements = importList.map(
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
- if (!targetFolder) {
32
- throw new Error("targetFolder is not defined");
33
- }
34
- return {
35
- name: "markdown-examples",
36
- enforce: "pre",
37
- // before vue
38
- resolveId(id) {
39
- if (moduleIdRE.test(id)) {
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
- targetFolder = path;
49
- return vitePlugin(isProd);
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
- if (vendorRE.test(id)) {
56
- return "vendor";
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.9",
3
+ "version": "1.1.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.0.16"
44
+ "vite": "^8.1.4"
45
45
  },
46
46
  "scripts": {
47
- "build": "unbuild",
47
+ "build": "obuild && node ../../scripts/ensure-obuild-types.mjs",
48
48
  "clean": "rm -rf dist/ node_modules/"
49
49
  }
50
50
  }