@md-plugins/vite-examples-plugin 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +31 -15
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +5 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -30,13 +30,20 @@ pnpm add @md-plugins/vite-examples-plugin
|
|
|
30
30
|
|
|
31
31
|
To use the `viteExamplesPlugin`, configure it in your Vite project:
|
|
32
32
|
|
|
33
|
-
```
|
|
33
|
+
```typescript
|
|
34
34
|
import { defineConfig } from 'vite'
|
|
35
35
|
import vue from '@vitejs/plugin-vue'
|
|
36
|
-
import { viteExamplesPlugin } from '
|
|
36
|
+
import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin'
|
|
37
|
+
|
|
38
|
+
export default defineConfig(({ mode }) => {
|
|
39
|
+
const isProduction = mode === 'production'
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
return {
|
|
42
|
+
plugins: [
|
|
43
|
+
vue(),
|
|
44
|
+
viteExamplesPlugin({ isProd: isProduction, path: '/absolute/path/to/examples' }),
|
|
45
|
+
],
|
|
46
|
+
}
|
|
40
47
|
})
|
|
41
48
|
```
|
|
42
49
|
|
|
@@ -47,13 +54,20 @@ import { defineConfig } from 'vite'
|
|
|
47
54
|
import vue from '@vitejs/plugin-vue'
|
|
48
55
|
import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin'
|
|
49
56
|
|
|
50
|
-
export default defineConfig({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
export default defineConfig(({ mode }) => {
|
|
58
|
+
const isProduction = mode === 'production'
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
plugins: [
|
|
62
|
+
vue(),
|
|
63
|
+
viteExamplesPlugin({ isProd: isProduction, path: '/absolute/path/to/examples' }),
|
|
64
|
+
],
|
|
65
|
+
build: {
|
|
66
|
+
chunkSizeWarningLimit: 650,
|
|
67
|
+
rollupOptions: {
|
|
68
|
+
output: {
|
|
69
|
+
manualChunks: viteManualChunks,
|
|
70
|
+
},
|
|
57
71
|
},
|
|
58
72
|
},
|
|
59
73
|
},
|
|
@@ -74,7 +88,7 @@ export default defineConfig((ctx) => {
|
|
|
74
88
|
```js
|
|
75
89
|
build: {
|
|
76
90
|
vitePlugins: [
|
|
77
|
-
viteExamplesPlugin(ctx.appPaths.srcDir + '/examples'),
|
|
91
|
+
viteExamplesPlugin({ isProd: ctx.isProd, path: ctx.appPaths.srcDir + '/examples' }),
|
|
78
92
|
// ...
|
|
79
93
|
],
|
|
80
94
|
},
|
|
@@ -91,9 +105,7 @@ import { viteExamplesPlugin, viteManualChunks } from '@md-plugins/vite-examples-
|
|
|
91
105
|
build: {
|
|
92
106
|
extendViteConf(viteConf, { isClient }) {
|
|
93
107
|
if (ctx.prod && isClient) {
|
|
94
|
-
|
|
95
|
-
viteConf.build = {}
|
|
96
|
-
}
|
|
108
|
+
viteConf.build = viteConf.build || {}
|
|
97
109
|
viteConf.build.chunkSizeWarningLimit = 650
|
|
98
110
|
viteConf.build.rollupOptions = {
|
|
99
111
|
output: { manualChunks: viteManualChunks },
|
|
@@ -196,6 +208,10 @@ If the `targetFolder` is not defined when the plugin is initialized, an error wi
|
|
|
196
208
|
throw new Error('targetFolder is not defined')
|
|
197
209
|
```
|
|
198
210
|
|
|
211
|
+
## Documentation
|
|
212
|
+
|
|
213
|
+
In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/vite-plugins/viteexamplesplugin/overview) for the latest information.
|
|
214
|
+
|
|
199
215
|
## License
|
|
200
216
|
|
|
201
217
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -7,12 +7,23 @@ import { Plugin } from 'vite';
|
|
|
7
7
|
* that creates the actual Vite plugin. The returned plugin resolves and loads
|
|
8
8
|
* example code based on the production or development environment.
|
|
9
9
|
*
|
|
10
|
+
* @param isProd - A boolean indicating whether the Vite build is in production mode.
|
|
11
|
+
* This parameter determines whether the plugin will use the `prodLoad` or `devLoad` function for loading example code.
|
|
12
|
+
*
|
|
10
13
|
* @param path - The path to the directory containing the example files.
|
|
11
14
|
* This path will be used as the target folder for resolving examples.
|
|
15
|
+
* The `targetFolder` variable is set to this value before creating the Vite plugin.
|
|
12
16
|
*
|
|
13
17
|
* @returns A function that creates a Vite plugin.
|
|
18
|
+
* The returned function takes a boolean parameter `isProd` and returns a Vite plugin object.
|
|
19
|
+
* The plugin object has a `name`, `enforce`, `resolveId`, and `load` property.
|
|
20
|
+
* The `resolveId` property resolves module IDs starting with "examples:" and returns a resolved ID.
|
|
21
|
+
* The `load` property loads example code based on the production or development environment.
|
|
14
22
|
*/
|
|
15
|
-
declare function viteExamplesPlugin(isProd
|
|
23
|
+
declare function viteExamplesPlugin({ isProd, path }: {
|
|
24
|
+
isProd: boolean;
|
|
25
|
+
path: string;
|
|
26
|
+
}): Plugin;
|
|
16
27
|
|
|
17
28
|
/**
|
|
18
29
|
* A function to determine the manual chunk name for a given module ID.
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,23 @@ import { Plugin } from 'vite';
|
|
|
7
7
|
* that creates the actual Vite plugin. The returned plugin resolves and loads
|
|
8
8
|
* example code based on the production or development environment.
|
|
9
9
|
*
|
|
10
|
+
* @param isProd - A boolean indicating whether the Vite build is in production mode.
|
|
11
|
+
* This parameter determines whether the plugin will use the `prodLoad` or `devLoad` function for loading example code.
|
|
12
|
+
*
|
|
10
13
|
* @param path - The path to the directory containing the example files.
|
|
11
14
|
* This path will be used as the target folder for resolving examples.
|
|
15
|
+
* The `targetFolder` variable is set to this value before creating the Vite plugin.
|
|
12
16
|
*
|
|
13
17
|
* @returns A function that creates a Vite plugin.
|
|
18
|
+
* The returned function takes a boolean parameter `isProd` and returns a Vite plugin object.
|
|
19
|
+
* The plugin object has a `name`, `enforce`, `resolveId`, and `load` property.
|
|
20
|
+
* The `resolveId` property resolves module IDs starting with "examples:" and returns a resolved ID.
|
|
21
|
+
* The `load` property loads example code based on the production or development environment.
|
|
14
22
|
*/
|
|
15
|
-
declare function viteExamplesPlugin(isProd
|
|
23
|
+
declare function viteExamplesPlugin({ isProd, path }: {
|
|
24
|
+
isProd: boolean;
|
|
25
|
+
path: string;
|
|
26
|
+
}): Plugin;
|
|
16
27
|
|
|
17
28
|
/**
|
|
18
29
|
* A function to determine the manual chunk name for a given module ID.
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ function devLoad(id) {
|
|
|
10
10
|
return `export const code = import.meta.glob(${query}, { eager: true })
|
|
11
11
|
export const source = import.meta.glob(${query}, { query: '?raw', import: 'default', eager: true })`;
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return undefined;
|
|
14
14
|
}
|
|
15
15
|
function prodLoad(id) {
|
|
16
16
|
if (id.startsWith(resolvedIdPrefix)) {
|
|
@@ -25,7 +25,7 @@ import Raw${entry} from 'app/src/examples/${exampleId}/${entry}.vue?raw'`
|
|
|
25
25
|
return importStatements + `
|
|
26
26
|
export {${exportStatements}}`;
|
|
27
27
|
}
|
|
28
|
-
return
|
|
28
|
+
return undefined;
|
|
29
29
|
}
|
|
30
30
|
function vitePlugin(isProd) {
|
|
31
31
|
if (!targetFolder) {
|
|
@@ -39,12 +39,12 @@ function vitePlugin(isProd) {
|
|
|
39
39
|
if (moduleIdRE.test(id)) {
|
|
40
40
|
return "\0" + id;
|
|
41
41
|
}
|
|
42
|
-
return
|
|
42
|
+
return undefined;
|
|
43
43
|
},
|
|
44
44
|
load: isProd ? prodLoad : devLoad
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
function viteExamplesPlugin(isProd, path) {
|
|
47
|
+
function viteExamplesPlugin({ isProd, path }) {
|
|
48
48
|
targetFolder = path;
|
|
49
49
|
return vitePlugin(isProd);
|
|
50
50
|
}
|
|
@@ -60,7 +60,7 @@ function viteManualChunks(id) {
|
|
|
60
60
|
const name = examplesMatch[1] || examplesMatch[2];
|
|
61
61
|
return `e.${name}`;
|
|
62
62
|
}
|
|
63
|
-
return
|
|
63
|
+
return undefined;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
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-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"description": "A Vite plugin for @md-plugins for handling imported examples in markdown files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"
|
|
40
|
+
"devDependencies": {
|
|
41
41
|
"tinyglobby": "^0.2.10",
|
|
42
|
-
"vite": "^6.0.
|
|
42
|
+
"vite": "^6.0.7"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "unbuild",
|