@md-plugins/vite-examples-plugin 0.1.0-alpha.1 → 0.1.0-alpha.2

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024-present, Jeff Galbraith
3
+ Copyright (c) 2024-present, MD-PLUGINS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -31,21 +31,21 @@ pnpm add @md-plugins/vite-examples-plugin
31
31
  To use the `viteExamplesPlugin`, configure it in your Vite project:
32
32
 
33
33
  ```js
34
- import { defineConfig } from 'vite';
35
- import vue from '@vitejs/plugin-vue';
36
- import { viteExamplesPlugin } from '@md-plugin/vite-examples-plugin';
34
+ import { defineConfig } from 'vite'
35
+ import vue from '@vitejs/plugin-vue'
36
+ import { viteExamplesPlugin } from '@md-plugin/vite-examples-plugin'
37
37
 
38
38
  export default defineConfig({
39
39
  plugins: [vue(), viteExamplesPlugin('/absolute/path/to/examples')],
40
- });
40
+ })
41
41
  ```
42
42
 
43
43
  ### Manual Chunk Splitting with Vite
44
44
 
45
45
  ```js
46
- import { defineConfig } from 'vite';
47
- import vue from '@vitejs/plugin-vue';
48
- import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin';
46
+ import { defineConfig } from 'vite'
47
+ import vue from '@vitejs/plugin-vue'
48
+ import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin'
49
49
 
50
50
  export default defineConfig({
51
51
  plugins: [vue(), viteExamplesPlugin('/absolute/path/to/examples')],
@@ -57,7 +57,7 @@ export default defineConfig({
57
57
  },
58
58
  },
59
59
  },
60
- });
60
+ })
61
61
  ```
62
62
 
63
63
  ## Quasar Framework Configuration
@@ -84,10 +84,7 @@ export default defineConfig((ctx) => {
84
84
  ### Manual Chunk Splitting with Quasar
85
85
 
86
86
  ```js
87
- import {
88
- viteExamplesPlugin,
89
- viteManualChunks,
90
- } from '@md-plugins/vite-examples-plugin';
87
+ import { viteExamplesPlugin, viteManualChunks } from '@md-plugins/vite-examples-plugin'
91
88
  ```
92
89
 
93
90
  ```js
@@ -156,12 +153,12 @@ During development, the plugin uses Vite's `import.meta.glob` to dynamically loa
156
153
  ```ts
157
154
  export const code = import.meta.glob('/src/examples/example1/*.vue', {
158
155
  eager: true,
159
- });
156
+ })
160
157
  export const source = import.meta.glob('/src/examples/example1/*.vue', {
161
158
  query: '?raw',
162
159
  import: 'default',
163
160
  eager: true,
164
- });
161
+ })
165
162
  ```
166
163
 
167
164
  ### Production Mode
@@ -169,10 +166,10 @@ export const source = import.meta.glob('/src/examples/example1/*.vue', {
169
166
  In production, the plugin preloads example components and their raw source code, generating import and export statements:
170
167
 
171
168
  ```ts
172
- import Example1 from 'app/src/examples/example1/Example1.vue';
173
- import RawExample1 from 'app/src/examples/example1/Example1.vue?raw';
169
+ import Example1 from 'app/src/examples/example1/Example1.vue'
170
+ import RawExample1 from 'app/src/examples/example1/Example1.vue?raw'
174
171
 
175
- export { Example1, RawExample1 };
172
+ export { Example1, RawExample1 }
176
173
  ```
177
174
 
178
175
  ## Development Notes
@@ -196,7 +193,7 @@ The plugin is structured with the following components:
196
193
  If the `targetFolder` is not defined when the plugin is initialized, an error will be thrown:
197
194
 
198
195
  ```ts
199
- throw new Error('targetFolder is not defined');
196
+ throw new Error('targetFolder is not defined')
200
197
  ```
201
198
 
202
199
  ## License
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
1
3
  /**
2
4
  * Creates a Vite plugin for handling Markdown examples.
3
5
  *
@@ -8,16 +10,9 @@
8
10
  * @param path - The path to the directory containing the example files.
9
11
  * This path will be used as the target folder for resolving examples.
10
12
  *
11
- * @returns A function that creates a Vite plugin. This function takes a boolean
12
- * parameter indicating whether the build is in production mode and
13
- * returns the configured Vite plugin object.
13
+ * @returns A function that creates a Vite plugin.
14
14
  */
15
- declare function viteExamplesPlugin(path: string): (isProd: boolean) => {
16
- name: string;
17
- enforce: 'pre';
18
- resolveId(id: string): string | undefined;
19
- load(id: string): string | undefined;
20
- };
15
+ declare function viteExamplesPlugin(isProd: boolean, path: string): Plugin;
21
16
 
22
17
  /**
23
18
  * A function to determine the manual chunk name for a given module ID.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
1
3
  /**
2
4
  * Creates a Vite plugin for handling Markdown examples.
3
5
  *
@@ -8,16 +10,9 @@
8
10
  * @param path - The path to the directory containing the example files.
9
11
  * This path will be used as the target folder for resolving examples.
10
12
  *
11
- * @returns A function that creates a Vite plugin. This function takes a boolean
12
- * parameter indicating whether the build is in production mode and
13
- * returns the configured Vite plugin object.
13
+ * @returns A function that creates a Vite plugin.
14
14
  */
15
- declare function viteExamplesPlugin(path: string): (isProd: boolean) => {
16
- name: string;
17
- enforce: 'pre';
18
- resolveId(id: string): string | undefined;
19
- load(id: string): string | undefined;
20
- };
15
+ declare function viteExamplesPlugin(isProd: boolean, path: string): Plugin;
21
16
 
22
17
  /**
23
18
  * A function to determine the manual chunk name for a given module ID.
package/dist/index.mjs CHANGED
@@ -16,9 +16,7 @@ function prodLoad(id) {
16
16
  if (id.startsWith(resolvedIdPrefix)) {
17
17
  const exampleId = id.substring(id.indexOf(":") + 1);
18
18
  const files = globSync("*.vue", { cwd: join(targetFolder, exampleId) });
19
- const importList = files.map(
20
- (entry) => entry.substring(0, entry.length - 4)
21
- );
19
+ const importList = files.map((entry) => entry.substring(0, entry.length - 4));
22
20
  const importStatements = importList.map(
23
21
  (entry) => `import ${entry} from 'app/src/examples/${exampleId}/${entry}.vue'
24
22
  import Raw${entry} from 'app/src/examples/${exampleId}/${entry}.vue?raw'`
@@ -46,9 +44,9 @@ function vitePlugin(isProd) {
46
44
  load: isProd ? prodLoad : devLoad
47
45
  };
48
46
  }
49
- function viteExamplesPlugin(path) {
47
+ function viteExamplesPlugin(isProd, path) {
50
48
  targetFolder = path;
51
- return vitePlugin;
49
+ return vitePlugin(isProd);
52
50
  }
53
51
 
54
52
  const vendorRE = /node_modules[\\/](vue|@vue|quasar|vue-router)[\\/](.*)\.(m?js|css|sass)$/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@md-plugins/vite-examples-plugin",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "description": "A Vite plugin for @md-plugins for handling imported examples in markdown files.",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -38,10 +38,11 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "tinyglobby": "^0.2.10"
41
+ "tinyglobby": "^0.2.10",
42
+ "vite": "^6.0.6"
42
43
  },
43
44
  "scripts": {
44
45
  "build": "unbuild",
45
- "clean": "rm -rf dist"
46
+ "clean": "rm -rf dist/ node_modules/"
46
47
  }
47
48
  }