Skip to content

Commit 844a392

Browse files
committed
fix: react and vue component library setup
1 parent 2eeef32 commit 844a392

9 files changed

+36
-29
lines changed

package.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@
2929
"exports": {
3030
"./vue": {
3131
"types": "./dist/vue/index.d.ts",
32-
"import": "./dist/vue/index.es.js",
33-
"require": "./dist/vue/index.umd.js"
32+
"import": "./dist/vue/index.js"
3433
},
3534
"./react": {
3635
"types": "./dist/react/index.d.ts",
37-
"import": "./dist/react/index.es.js",
38-
"require": "./dist/react/index.umd.js"
36+
"import": "./dist/react/index.js"
3937
}
4038
},
41-
"main": "./dist/vue/index.umd.js",
42-
"module": "./dist/vue/index.es.js",
43-
"types": "./dist/vue/index.d.ts",
4439
"files": [
4540
"dist",
4641
"README.md",

src/react/Button.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> {
1+
export interface Props extends React.ButtonHTMLAttributes<HTMLButtonElement> {
22
label: string;
33
children?: React.ReactNode;
44
}
55

6-
function Button(props: Props) {
6+
function Button(props: Props): JSX.Element {
77
const { className, label, ...restProps } = props;
88
return (
99
<button

src/vue-shim.d.ts

-5
This file was deleted.

src/vue/Button.vue

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,21 @@
33
</template>
44

55
<script setup lang="ts">
6-
defineProps<{ label: string }>();
6+
import { defineComponent } from 'vue';
7+
8+
defineComponent({
9+
name: 'Button',
10+
props: {
11+
label: String
12+
},
13+
setup(props) {
14+
return {
15+
label: props.label
16+
};
17+
}
18+
});
19+
20+
defineProps<{
21+
label: String;
22+
}>();
723
</script>

src/vue/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import Button from './Button.vue';
2-
32
export { Button };

tsconfig.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"declarationDir": "./dist/types",
54
"emitDeclarationOnly": true,
65
"module": "ESNext",
76
"moduleResolution": "node",
87
"esModuleInterop": true,
98
"skipLibCheck": true,
9+
"jsx": "react-jsx",
1010

11-
"baseUrl": ".",
11+
"baseUrl": "./",
1212
"paths": {
13-
"@vue/*": ["src/vue/*"],
14-
"@react/*": ["src/react/*"]
13+
"vue/*": ["src/vue/*"],
14+
"react/*": ["src/react/*"]
1515
},
1616
"strict": true,
17-
"jsx": "react-jsx",
1817
"lib": ["dom", "esnext"],
1918
"allowSyntheticDefaultImports": true
2019
},

tsconfig.react.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"declarationDir": "./dist/react/types",
45
"outDir": "dist/react"
56
},
67
"include": ["src/react/**/*", "src/react-entry.ts"],

tsconfig.vue.json

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"declarationDir": "./dist/vue/types",
45
"outDir": "dist/vue"
56
},
7+
"jsx": "",
68
"include": ["src/vue/**/*", "src/vue-entry.ts"],
79
"exclude": ["src/react/**/*"]
810
}

vite.config.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { resolve } from 'path';
99
export default defineConfig(({ mode }) => {
1010
const isVue = mode === 'vue';
1111
const framework = isVue ? 'vue' : 'react';
12+
const global = (
13+
isVue ? { vue: 'Vue' } : { react: 'React', 'react/jsx-runtime': 'JSX' }
14+
) as { [key: string]: string };
1215

1316
return {
1417
plugins: [
@@ -32,20 +35,17 @@ export default defineConfig(({ mode }) => {
3235
entry: resolve(__dirname, `src/${framework}-entry.ts`),
3336
// name: isVue ? 'GMotionVue' : 'GMotionReact',
3437
name: 'G-Motion',
35-
formats: ['es', 'umd'],
38+
formats: ['es'],
3639
fileName: 'index'
3740
// fileName: (format) => `index.${format}.js`
3841
},
3942
rollupOptions: {
4043
external: ['vue', 'react', 'react/jsx-runtime'],
4144
output: {
42-
assetFileNames: 'assets/[name][extname]',
43-
entryFileNames: '[name].js',
44-
globals: {
45-
vue: 'Vue',
46-
react: 'React'
47-
},
48-
exports: 'named'
45+
// assetFileNames: 'assets/[name][extname]',
46+
// entryFileNames: 'index.js',
47+
exports: 'named',
48+
globals: global
4949
}
5050
}
5151
},

0 commit comments

Comments
 (0)