xieyaxin 12 months ago
commit
4e4e128ffa
  1. 2
      .gitignore
  2. 13
      dev.ts
  3. 14
      index.html
  4. 25
      package.json
  5. 8285
      pnpm-lock.yaml
  6. 27
      somebuild.config.mts
  7. 38
      src/components/VaguerButton/VaguerButton.vue
  8. 6
      src/components/VaguerButton/index.ts
  9. 18
      src/components/index.ts
  10. 17
      src/index.ts
  11. 5
      src/shims-vue.d.ts
  12. 13
      tsconfig.json

2
.gitignore

@ -0,0 +1,2 @@
node_modules
dist

13
dev.ts

@ -0,0 +1,13 @@
import Vue from "vue";
import { VaguerComponents } from "./dist/comp-demo-vue2";
Vue.use(VaguerComponents);
const app = new Vue({
methods: {
handleClick() {
alert("222");
},
},
});
app.$mount("#app");

14
index.html

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="app">
<vaguer-button @click.native="handleClick">aa</vaguer-button>
</div>
<script type="module" src="/dev.ts"></script>
</body>
</html>

25
package.json

@ -0,0 +1,25 @@
{
"name": "comp-demo-vue2",
"type": "module",
"private": true,
"scripts": {
"watch": "somebuild build --watch",
"dev": "somebuild dev",
"build": "somebuild build"
},
"globals": {
"vue": "Vue"
},
"dependencies": {
"vue": "2.6.14",
"vue-template-compiler": "2.6.14"
},
"devDependencies": {
"@somebuild/build-component-vue2": "^0.0.3",
"somebuild": "^0.0.17"
},
"volta": {
"node": "18.17.1",
"pnpm": "9.0.6"
}
}

8285
pnpm-lock.yaml

File diff suppressed because it is too large

27
somebuild.config.mts

@ -0,0 +1,27 @@
import { defineRootConfig } from "somebuild";
import fs from "node:fs";
const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url), "utf8"));
const json = loadJSON("./package.json");
export default defineRootConfig({
mode: "component-vue2",
"component-vue2": {
less27: true,
outDir: "./dist",
name: json.name,
dtsEntryRoot: "src",
entry: "src/index.ts",
config: {
vite: {
resolve: {
alias: {
"@": "./src",
vue: "vue/dist/vue.esm.js",
},
},
},
},
},
});

38
src/components/VaguerButton/VaguerButton.vue

@ -0,0 +1,38 @@
<script>
export default {
data(){
return {
a: 123
}
}
}
</script>
<template>
<button class="vaguer-button">
<slot />-{{ a }}
</button>
</template>
<style lang="scss">
.vaguer-button {
color: red;
// @apply
// border-none
// bg-teal-500
// text-white
// font-bold
// px-4
// py-2
// rounded
// cursor-pointer
// transform
// duration-100
// ease-in-out
// hover:(bg-teal-600)
// active:(scale-90);
}
</style>

6
src/components/VaguerButton/index.ts

@ -0,0 +1,6 @@
import VaguerButton from "./VaguerButton.vue"
export {
VaguerButton
}
export default VaguerButton

18
src/components/index.ts

@ -0,0 +1,18 @@
// const components = import.meta.globEager("./**/*.vue");
// const exportable: any = {};
// function getName(key: string) {
// return key
// .substring(location.pathname.lastIndexOf("/") + 2)
// .split(".vue")[0];
// }
// Object.entries(components).forEach(([key, value]) => {
// exportable[value.name ? value.name : getName(key)] = value.default;
// });
// export default exportable;
import VaguerButton from "./VaguerButton/VaguerButton.vue";
export { VaguerButton };

17
src/index.ts

@ -0,0 +1,17 @@
import type { PluginObject } from "vue";
import * as components from "./components";
export default components;
export const VaguerComponents: PluginObject<{}> = {
install(app) {
Object.entries(components).forEach(([key, value]: [string, any]) => {
app.component(key, value);
});
},
};
console.log(22);
// START_EXPORTS
export { default as VaguerButton } from "./components/VaguerButton";
// END_EXPORTS

5
src/shims-vue.d.ts

@ -0,0 +1,5 @@
declare module '*.vue' {
import { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

13
tsconfig.json

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"exclude": ["node_modules", ".output"]
}
Loading…
Cancel
Save