@md-plugins/vite-examples-plugin 0.1.0-alpha.1 → 0.1.0-alpha.11
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 +1 -1
- package/README.md +46 -33
- package/dist/index.d.mts +15 -9
- package/dist/index.d.ts +15 -9
- package/dist/index.mjs +3 -5
- package/package.json +5 -4
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2024-present,
|
|
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
|
@@ -30,34 +30,48 @@ pnpm add @md-plugins/vite-examples-plugin
|
|
|
30
30
|
|
|
31
31
|
To use the `viteExamplesPlugin`, configure it in your Vite project:
|
|
32
32
|
|
|
33
|
-
```
|
|
34
|
-
import { defineConfig } from 'vite'
|
|
35
|
-
import vue from '@vitejs/plugin-vue'
|
|
36
|
-
import { viteExamplesPlugin } from '
|
|
37
|
-
|
|
38
|
-
export default defineConfig({
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
```typescript
|
|
34
|
+
import { defineConfig } from 'vite'
|
|
35
|
+
import vue from '@vitejs/plugin-vue'
|
|
36
|
+
import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin'
|
|
37
|
+
|
|
38
|
+
export default defineConfig(({ mode }) => {
|
|
39
|
+
const isProduction = mode === 'production'
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
plugins: [
|
|
43
|
+
vue(),
|
|
44
|
+
viteExamplesPlugin({ isProd: isProduction, path: '/absolute/path/to/examples' }),
|
|
45
|
+
],
|
|
46
|
+
}
|
|
47
|
+
})
|
|
41
48
|
```
|
|
42
49
|
|
|
43
50
|
### Manual Chunk Splitting with Vite
|
|
44
51
|
|
|
45
52
|
```js
|
|
46
|
-
import { defineConfig } from 'vite'
|
|
47
|
-
import vue from '@vitejs/plugin-vue'
|
|
48
|
-
import { viteExamplesPlugin, viteManualChunks } from 'vite-examples-plugin'
|
|
53
|
+
import { defineConfig } from 'vite'
|
|
54
|
+
import vue from '@vitejs/plugin-vue'
|
|
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
|
},
|
|
60
|
-
})
|
|
74
|
+
})
|
|
61
75
|
```
|
|
62
76
|
|
|
63
77
|
## Quasar Framework Configuration
|
|
@@ -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
|
},
|
|
@@ -84,19 +98,14 @@ export default defineConfig((ctx) => {
|
|
|
84
98
|
### Manual Chunk Splitting with Quasar
|
|
85
99
|
|
|
86
100
|
```js
|
|
87
|
-
import {
|
|
88
|
-
viteExamplesPlugin,
|
|
89
|
-
viteManualChunks,
|
|
90
|
-
} from '@md-plugins/vite-examples-plugin';
|
|
101
|
+
import { viteExamplesPlugin, viteManualChunks } from '@md-plugins/vite-examples-plugin'
|
|
91
102
|
```
|
|
92
103
|
|
|
93
104
|
```js
|
|
94
105
|
build: {
|
|
95
106
|
extendViteConf(viteConf, { isClient }) {
|
|
96
107
|
if (ctx.prod && isClient) {
|
|
97
|
-
|
|
98
|
-
viteConf.build = {}
|
|
99
|
-
}
|
|
108
|
+
viteConf.build = viteConf.build || {}
|
|
100
109
|
viteConf.build.chunkSizeWarningLimit = 650
|
|
101
110
|
viteConf.build.rollupOptions = {
|
|
102
111
|
output: { manualChunks: viteManualChunks },
|
|
@@ -156,12 +165,12 @@ During development, the plugin uses Vite's `import.meta.glob` to dynamically loa
|
|
|
156
165
|
```ts
|
|
157
166
|
export const code = import.meta.glob('/src/examples/example1/*.vue', {
|
|
158
167
|
eager: true,
|
|
159
|
-
})
|
|
168
|
+
})
|
|
160
169
|
export const source = import.meta.glob('/src/examples/example1/*.vue', {
|
|
161
170
|
query: '?raw',
|
|
162
171
|
import: 'default',
|
|
163
172
|
eager: true,
|
|
164
|
-
})
|
|
173
|
+
})
|
|
165
174
|
```
|
|
166
175
|
|
|
167
176
|
### Production Mode
|
|
@@ -169,10 +178,10 @@ export const source = import.meta.glob('/src/examples/example1/*.vue', {
|
|
|
169
178
|
In production, the plugin preloads example components and their raw source code, generating import and export statements:
|
|
170
179
|
|
|
171
180
|
```ts
|
|
172
|
-
import Example1 from 'app/src/examples/example1/Example1.vue'
|
|
173
|
-
import RawExample1 from 'app/src/examples/example1/Example1.vue?raw'
|
|
181
|
+
import Example1 from 'app/src/examples/example1/Example1.vue'
|
|
182
|
+
import RawExample1 from 'app/src/examples/example1/Example1.vue?raw'
|
|
174
183
|
|
|
175
|
-
export { Example1, RawExample1 }
|
|
184
|
+
export { Example1, RawExample1 }
|
|
176
185
|
```
|
|
177
186
|
|
|
178
187
|
## Development Notes
|
|
@@ -196,9 +205,13 @@ The plugin is structured with the following components:
|
|
|
196
205
|
If the `targetFolder` is not defined when the plugin is initialized, an error will be thrown:
|
|
197
206
|
|
|
198
207
|
```ts
|
|
199
|
-
throw new Error('targetFolder is not defined')
|
|
208
|
+
throw new Error('targetFolder is not defined')
|
|
200
209
|
```
|
|
201
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
|
+
|
|
202
215
|
## License
|
|
203
216
|
|
|
204
217
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
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
|
*
|
|
@@ -5,19 +7,23 @@
|
|
|
5
7
|
* that creates the actual Vite plugin. The returned plugin resolves and loads
|
|
6
8
|
* example code based on the production or development environment.
|
|
7
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
|
+
*
|
|
8
13
|
* @param path - The path to the directory containing the example files.
|
|
9
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.
|
|
10
16
|
*
|
|
11
|
-
* @returns A function that creates a Vite plugin.
|
|
12
|
-
*
|
|
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(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
load(id: string): string | undefined;
|
|
20
|
-
};
|
|
23
|
+
declare function viteExamplesPlugin({ isProd, path }: {
|
|
24
|
+
isProd: boolean;
|
|
25
|
+
path: string;
|
|
26
|
+
}): Plugin;
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* 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
|
*
|
|
@@ -5,19 +7,23 @@
|
|
|
5
7
|
* that creates the actual Vite plugin. The returned plugin resolves and loads
|
|
6
8
|
* example code based on the production or development environment.
|
|
7
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
|
+
*
|
|
8
13
|
* @param path - The path to the directory containing the example files.
|
|
9
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.
|
|
10
16
|
*
|
|
11
|
-
* @returns A function that creates a Vite plugin.
|
|
12
|
-
*
|
|
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(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
load(id: string): string | undefined;
|
|
20
|
-
};
|
|
23
|
+
declare function viteExamplesPlugin({ isProd, path }: {
|
|
24
|
+
isProd: boolean;
|
|
25
|
+
path: string;
|
|
26
|
+
}): Plugin;
|
|
21
27
|
|
|
22
28
|
/**
|
|
23
29
|
* 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.
|
|
3
|
+
"version": "0.1.0-alpha.11",
|
|
4
4
|
"description": "A Vite plugin for @md-plugins for handling imported examples in markdown files.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"
|
|
41
|
-
"tinyglobby": "^0.2.10"
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tinyglobby": "^0.2.10",
|
|
42
|
+
"vite": "^6.0.7"
|
|
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
|
}
|