Skip to content

Commit 5725d22

Browse files
Chrystiam Nascimento JuniorChrystiam Nascimento Junior
authored andcommitted
feat(Vite): Adjust project to build with vite
1 parent 4381c01 commit 5725d22

File tree

7 files changed

+598
-16
lines changed

7 files changed

+598
-16
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
GH_TOKEN: ${{ env.GH_TOKEN }}
5555

5656
- name: Build package
57-
run: yarn prepack
57+
run: yarn build
5858

5959
- name: Create release
6060
run: npx semantic-release

.gitignore

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@ android/keystores/debug.keystore
6969
# generated by bob
7070
lib/
7171

72+
# Nuxt.js build / generate output
73+
.nuxt
74+
dist
75+
7276
.env
7377
web-build
7478

75-
.yarn/*
76-
!.yarn/patches
77-
!.yarn/plugins
78-
!.yarn/releases
79-
!.yarn/sdks
80-
!.yarn/versions
79+
# yarn v2
80+
.yarn/cache
81+
.yarn/unplugged
82+
.yarn/build-state.yml
83+
.yarn/install-state.gz
84+
.pnp.*

index.d.ts

Whitespace-only changes.

package.json

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
22
"name": "@lawnstarter/react-native-ui-datepicker",
33
"version": "2.0.11",
4+
"type": "module",
45
"description": "Customizable date picker for React Native",
5-
"main": "lib/commonjs/index",
6-
"module": "lib/module/index",
7-
"types": "lib/typescript/index.d.ts",
8-
"react-native": "src/index",
6+
"types": "dist/index.d.ts",
7+
"main": "./dist/react-native-ui-datepicker.cjs",
8+
"module": "./dist/react-native-ui-datepicker.js",
9+
"react-native": "./dist/react-native-ui-datepicker.js",
910
"source": "src/index",
1011
"files": [
1112
"src",
@@ -31,7 +32,7 @@
3132
"test": "jest",
3233
"typecheck": "tsc --noEmit",
3334
"lint": "eslint .",
34-
"prepack": "bob build"
35+
"build": "vite build"
3536
},
3637
"keywords": [
3738
"react-native",
@@ -65,6 +66,45 @@
6566
"publishConfig": {
6667
"registry": "https://registry.npmjs.org/"
6768
},
69+
"exports": {
70+
".": {
71+
"import": "./dist/react-native-ui-datepicker.js",
72+
"require": "./dist/react-native-ui-datepicker.cjs",
73+
"types": "./dist/index.d.ts"
74+
},
75+
"./types": {
76+
"types": "./dist/react-native-ui-datepicker/src/types.d.ts",
77+
"require": "./dist/react-native-ui-datepicker/types.cjs",
78+
"import": "./dist/react-native-ui-datepicker/types.js",
79+
"react-native": "./dist/react-native-ui-datepicker/types.js"
80+
},
81+
"./enums": {
82+
"types": "./dist/react-native-ui-datepicker/src/enums.d.ts",
83+
"require": "./dist/react-native-ui-datepicker/enums.cjs",
84+
"import": "./dist/react-native-ui-datepicker/enums.js",
85+
"react-native": "./dist/react-native-ui-datepicker/enums.js"
86+
},
87+
"./utils": {
88+
"types": "./dist/react-native-ui-datepicker/src/utils.d.ts",
89+
"require": "./dist/react-native-ui-datepicker/utils.cjs",
90+
"import": "./dist/react-native-ui-datepicker/utils.js",
91+
"react-native": "./dist/react-native-ui-datepicker/utils.js"
92+
},
93+
"./assets/*": "./dist/assets/*"
94+
},
95+
"typesVersions": {
96+
"*": {
97+
"types": [
98+
"./dist/react-native-ui-datepicker/src/types.d.ts"
99+
],
100+
"enums": [
101+
"./dist/react-native-ui-datepicker/src/enums.d.ts"
102+
],
103+
"utils": [
104+
"./dist/react-native-ui-datepicker/src/utils.d.ts"
105+
]
106+
}
107+
},
68108
"devDependencies": {
69109
"@evilmartians/lefthook": "^1.2.2",
70110
"@react-native-community/eslint-config": "^3.0.2",
@@ -80,6 +120,7 @@
80120
"@types/react": "18.2.0",
81121
"@types/react-native": "0.72.0",
82122
"@types/react-test-renderer": "^18.0.0",
123+
"@vitejs/plugin-react-swc": "^3.5.0",
83124
"commitizen": "^4.3.0",
84125
"commitlint": "^17.0.2",
85126
"cz-ls-commits": "^1.1.0",
@@ -96,7 +137,9 @@
96137
"react-test-renderer": "18.2.0",
97138
"semantic-release": "^22.0.12",
98139
"ts-node": "^10.9.1",
99-
"typescript": "^4.5.2"
140+
"typescript": "^4.5.2",
141+
"vite": "^4.5.9",
142+
"vite-plugin-copy": "^0.1.6"
100143
},
101144
"resolutions": {
102145
"@types/react": "18.2.0",

vite.build.helpers.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { readFileSync } from 'fs';
2+
import * as esbuild from 'esbuild';
3+
4+
export const extensions = [
5+
'.mjs',
6+
'.tsx',
7+
'.ts',
8+
'.jsx',
9+
'.js',
10+
'.css',
11+
'.json',
12+
];
13+
14+
export const rollupPlugin = (matchers: RegExp[]) => ({
15+
name: 'js-in-jsx',
16+
load(id: string) {
17+
if (matchers.some((matcher) => matcher.test(id)) && id.endsWith('.js')) {
18+
const file = readFileSync(id, { encoding: 'utf-8' });
19+
return esbuild.transformSync(file, { loader: 'jsx', jsx: 'automatic' });
20+
}
21+
22+
return null;
23+
},
24+
});

vite.config.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import react from '@vitejs/plugin-react-swc';
2+
import { defineConfig } from 'vite';
3+
// @ts-ignore
4+
import { copy } from 'vite-plugin-copy';
5+
6+
import { extensions } from './vite.build.helpers';
7+
8+
export default defineConfig({
9+
plugins: [react(), copy([{ src: './src/assets', dest: 'dist' }])],
10+
build: {
11+
outDir: 'dist',
12+
sourcemap: true,
13+
emptyOutDir: true,
14+
lib: {
15+
name: '@lawnstarter/react-native-ui-datepicker',
16+
entry: {
17+
index: 'src/index.ts',
18+
enums: 'src/enums.ts',
19+
types: 'src/types.ts',
20+
utils: 'src/utils.ts',
21+
},
22+
fileName: (moduleFormat, entryName) => {
23+
const extension = moduleFormat === 'es' ? 'js' : moduleFormat;
24+
return `${entryName}.${extension}`;
25+
},
26+
},
27+
rollupOptions: {
28+
external: ['react', 'dayjs', 'react-native'],
29+
},
30+
},
31+
optimizeDeps: {
32+
esbuildOptions: {
33+
resolveExtensions: extensions,
34+
loader: { '.js': 'jsx' },
35+
jsx: 'automatic',
36+
},
37+
},
38+
resolve: {
39+
extensions: extensions,
40+
},
41+
esbuild: {
42+
loader: 'tsx',
43+
},
44+
});

0 commit comments

Comments
 (0)