vue-plugin-template-test 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/LICENSE +21 -0
- package/README.md +181 -0
- package/dist/index.cjs +1 -0
- package/dist/index.mjs +55 -0
- package/dist/vue-plugin-template-test.css +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Vue Plugin Template
|
|
2
|
+
|
|
3
|
+
A comprehensive template for creating Vue 3 plugins with TypeScript, testing, and development tools pre-configured.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Vue 3** support with TypeScript
|
|
8
|
+
- ✅ **Local playground** for testing your plugin during development
|
|
9
|
+
- ✅ **Unit testing** with Vitest and Vue Test Utils
|
|
10
|
+
- ✅ **Linting** with ESLint and Prettier
|
|
11
|
+
- ✅ **GitHub Actions** CI/CD pipeline
|
|
12
|
+
- ✅ **Build configuration** for npm package publishing
|
|
13
|
+
- ✅ **Example components** and composables
|
|
14
|
+
|
|
15
|
+
## 🏁 Getting Started
|
|
16
|
+
|
|
17
|
+
### 1. Clone this template
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
git clone https://github.com/monterail/vue-plugin-template.git
|
|
21
|
+
cd vue-plugin-template
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### 2. Install dependencies
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 3. Customize your plugin
|
|
31
|
+
|
|
32
|
+
Update the following files:
|
|
33
|
+
|
|
34
|
+
- `package.json` - Change name, description, author, etc.
|
|
35
|
+
- `src/index.ts` - Rename your plugin and customize functionality
|
|
36
|
+
- `src/components/` - Add or modify components
|
|
37
|
+
- `src/composables/` - Add or modify composables
|
|
38
|
+
- `README.md` - Update documentation for your plugin
|
|
39
|
+
|
|
40
|
+
### 4. Start development
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Run the playground for local development
|
|
44
|
+
npm run dev
|
|
45
|
+
|
|
46
|
+
# Or run tests in watch mode
|
|
47
|
+
npm run test:watch
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 🛠️ Development
|
|
51
|
+
|
|
52
|
+
### Basic Plugin Structure
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// src/index.ts
|
|
56
|
+
import type { App, Plugin } from 'vue'
|
|
57
|
+
|
|
58
|
+
export interface MyPluginOptions {
|
|
59
|
+
// Your options here
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const MyPlugin: Plugin = {
|
|
63
|
+
install(app: App, options: MyPluginOptions = {}) {
|
|
64
|
+
// Register components
|
|
65
|
+
app.component('MyComponent', MyComponent)
|
|
66
|
+
|
|
67
|
+
// Add global properties
|
|
68
|
+
app.config.globalProperties.$myPlugin = {
|
|
69
|
+
// Your global methods
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Provide data
|
|
73
|
+
app.provide('myData', someData)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default MyPlugin
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Registering Components
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// Register globally
|
|
84
|
+
app.component('MyComponent', MyComponent)
|
|
85
|
+
|
|
86
|
+
// Register with prefix
|
|
87
|
+
const prefix = options.prefix || 'My'
|
|
88
|
+
app.component(`${prefix}Component`, MyComponent)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Adding Global Properties
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
app.config.globalProperties.$myPlugin = {
|
|
95
|
+
greet: (name: string) => `Hello, ${name}!`
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// TypeScript types
|
|
99
|
+
declare module '@vue/runtime-core' {
|
|
100
|
+
export interface ComponentCustomProperties {
|
|
101
|
+
$myPlugin: {
|
|
102
|
+
greet: (name: string) => string
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Creating Composables
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// src/composables/useMyPlugin.ts
|
|
112
|
+
import { ref, computed } from 'vue'
|
|
113
|
+
|
|
114
|
+
export function useMyPlugin() {
|
|
115
|
+
const count = ref(0)
|
|
116
|
+
const double = computed(() => count.value * 2)
|
|
117
|
+
|
|
118
|
+
const increment = () => count.value++
|
|
119
|
+
|
|
120
|
+
return { count, double, increment }
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 🔧 Using Your Published Plugin
|
|
125
|
+
|
|
126
|
+
Once published, users can install and use your plugin:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install your-plugin-name
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
// main.ts
|
|
134
|
+
import { createApp } from 'vue'
|
|
135
|
+
import App from './App.vue'
|
|
136
|
+
import MyPlugin from 'your-plugin-name'
|
|
137
|
+
|
|
138
|
+
const app = createApp(App)
|
|
139
|
+
|
|
140
|
+
app.use(MyPlugin, {
|
|
141
|
+
// Plugin options
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
app.mount('#app')
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```vue
|
|
148
|
+
<!-- Using in components -->
|
|
149
|
+
<template>
|
|
150
|
+
<MyComponent />
|
|
151
|
+
</template>
|
|
152
|
+
|
|
153
|
+
<script setup>
|
|
154
|
+
import { useMyPlugin } from 'your-plugin-name'
|
|
155
|
+
|
|
156
|
+
const { count, increment } = useMyPlugin()
|
|
157
|
+
</script>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 🤝 Contributing
|
|
161
|
+
|
|
162
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
163
|
+
|
|
164
|
+
## 📄 License
|
|
165
|
+
|
|
166
|
+
MIT
|
|
167
|
+
|
|
168
|
+
## 🙏 Acknowledgments
|
|
169
|
+
|
|
170
|
+
Built with:
|
|
171
|
+
- [Vue 3](https://vuejs.org/)
|
|
172
|
+
- [Vite](https://vitejs.dev/)
|
|
173
|
+
- [Vitest](https://vitest.dev/)
|
|
174
|
+
- [TypeScript](https://www.typescriptlang.org/)
|
|
175
|
+
- [Vue Test Utils](https://test-utils.vuejs.org/)
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
**Happy plugin building! 🎉**
|
|
180
|
+
|
|
181
|
+
If you find this template helpful, please give it a ⭐️ on GitHub!
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r={class:"my-component"},s=e.defineComponent({__name:"MyComponent",props:{title:{default:"My Component"},message:{default:"This is a sample component from the Vue plugin template"},buttonText:{default:"Click me"}},emits:["click"],setup(t,{emit:n}){const o=n,l=e.ref(0),c=()=>{l.value++,o("click",`Button clicked ${l.value} times`)};return(u,f)=>(e.openBlock(),e.createElementBlock("div",r,[e.createElementVNode("h2",null,e.toDisplayString(t.title),1),e.createElementVNode("p",null,e.toDisplayString(t.message),1),e.createElementVNode("button",{onClick:c},e.toDisplayString(t.buttonText),1)]))}}),m=(t,n)=>{const o=t.__vccOpts||t;for(const[l,c]of n)o[l]=c;return o},i=m(s,[["__scopeId","data-v-9516f9b4"]]);function a(){const t=e.inject("myPluginPrefix","Default"),n=e.ref(0),o=e.computed(()=>n.value*2);return{prefix:t,count:n,doubleCount:o,increment:()=>{n.value++},decrement:()=>{n.value--},reset:()=>{n.value=0}}}const p={install(t,n={}){const{prefix:o="My",globalProperty:l=!0}=n;t.component(`${o}Component`,i),l&&(t.config.globalProperties.$myPlugin={greet:c=>`Hello from MyPlugin, ${c}!`}),t.provide("myPluginPrefix",o)}};exports.MyComponent=i;exports.MyPlugin=p;exports.useMyPlugin=a;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { defineComponent as r, ref as s, createElementBlock as m, openBlock as a, createElementVNode as l, toDisplayString as i, inject as f, computed as p } from "vue";
|
|
2
|
+
const d = { class: "my-component" }, g = /* @__PURE__ */ r({
|
|
3
|
+
__name: "MyComponent",
|
|
4
|
+
props: {
|
|
5
|
+
title: { default: "My Component" },
|
|
6
|
+
message: { default: "This is a sample component from the Vue plugin template" },
|
|
7
|
+
buttonText: { default: "Click me" }
|
|
8
|
+
},
|
|
9
|
+
emits: ["click"],
|
|
10
|
+
setup(e, { emit: t }) {
|
|
11
|
+
const n = t, o = s(0), c = () => {
|
|
12
|
+
o.value++, n("click", `Button clicked ${o.value} times`);
|
|
13
|
+
};
|
|
14
|
+
return (u, k) => (a(), m("div", d, [
|
|
15
|
+
l("h2", null, i(e.title), 1),
|
|
16
|
+
l("p", null, i(e.message), 1),
|
|
17
|
+
l("button", { onClick: c }, i(e.buttonText), 1)
|
|
18
|
+
]));
|
|
19
|
+
}
|
|
20
|
+
}), y = (e, t) => {
|
|
21
|
+
const n = e.__vccOpts || e;
|
|
22
|
+
for (const [o, c] of t)
|
|
23
|
+
n[o] = c;
|
|
24
|
+
return n;
|
|
25
|
+
}, v = /* @__PURE__ */ y(g, [["__scopeId", "data-v-9516f9b4"]]);
|
|
26
|
+
function P() {
|
|
27
|
+
const e = f("myPluginPrefix", "Default"), t = s(0), n = p(() => t.value * 2);
|
|
28
|
+
return {
|
|
29
|
+
prefix: e,
|
|
30
|
+
count: t,
|
|
31
|
+
doubleCount: n,
|
|
32
|
+
increment: () => {
|
|
33
|
+
t.value++;
|
|
34
|
+
},
|
|
35
|
+
decrement: () => {
|
|
36
|
+
t.value--;
|
|
37
|
+
},
|
|
38
|
+
reset: () => {
|
|
39
|
+
t.value = 0;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const _ = {
|
|
44
|
+
install(e, t = {}) {
|
|
45
|
+
const { prefix: n = "My", globalProperty: o = !0 } = t;
|
|
46
|
+
e.component(`${n}Component`, v), o && (e.config.globalProperties.$myPlugin = {
|
|
47
|
+
greet: (c) => `Hello from MyPlugin, ${c}!`
|
|
48
|
+
}), e.provide("myPluginPrefix", n);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export {
|
|
52
|
+
v as MyComponent,
|
|
53
|
+
_ as MyPlugin,
|
|
54
|
+
P as useMyPlugin
|
|
55
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.my-component[data-v-9516f9b4]{padding:1.5rem;border:2px solid #42b883;border-radius:8px;background-color:#f9f9f9;text-align:center;max-width:400px;margin:0 auto}.my-component h2[data-v-9516f9b4]{color:#42b883;margin-top:0}.my-component p[data-v-9516f9b4]{color:#333;line-height:1.6}.my-component button[data-v-9516f9b4]{padding:.5rem 1.5rem;background-color:#42b883;color:#fff;border:none;border-radius:4px;cursor:pointer;font-size:1rem;transition:background-color .3s}.my-component button[data-v-9516f9b4]:hover{background-color:#35a372}.my-component button[data-v-9516f9b4]:active{transform:translateY(1px)}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vue-plugin-template-test",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A template for creating Vue plugins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "npm run playground",
|
|
21
|
+
"playground": "vite --config vite.playground.config.ts",
|
|
22
|
+
"build": "vite build && vue-tsc --project tsconfig.app.json --emitDeclarationOnly",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:ui": "vitest --ui",
|
|
26
|
+
"lint": "eslint .",
|
|
27
|
+
"format": "prettier --write src/ playground/ tests/",
|
|
28
|
+
"typecheck": "vue-tsc --noEmit",
|
|
29
|
+
"prepublishOnly": "npm run build"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"vue",
|
|
33
|
+
"vue3",
|
|
34
|
+
"plugin",
|
|
35
|
+
"template"
|
|
36
|
+
],
|
|
37
|
+
"author": "",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vue": "^3.5.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@tsconfig/node20": "^20.1.4",
|
|
44
|
+
"@types/node": "^22.10.5",
|
|
45
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
46
|
+
"@vitest/ui": "^2.1.8",
|
|
47
|
+
"@vue/eslint-config-prettier": "^10.1.0",
|
|
48
|
+
"@vue/eslint-config-typescript": "^14.1.3",
|
|
49
|
+
"@vue/test-utils": "^2.4.6",
|
|
50
|
+
"eslint": "^9.17.0",
|
|
51
|
+
"eslint-plugin-vue": "^9.31.0",
|
|
52
|
+
"jsdom": "^25.0.1",
|
|
53
|
+
"prettier": "^3.4.2",
|
|
54
|
+
"typescript": "~5.7.2",
|
|
55
|
+
"vite": "^6.0.7",
|
|
56
|
+
"vitest": "^2.1.8",
|
|
57
|
+
"vue": "^3.5.13",
|
|
58
|
+
"vue-tsc": "^2.1.10"
|
|
59
|
+
}
|
|
60
|
+
}
|