Skip to content

Commit

Permalink
fix: emit .d.ts entrypoints for cross-env compat
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jul 25, 2022
1 parent c3513ff commit 97c4690
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
},
"scripts": {
"dev": "vite",
"build": "rimraf dist && npm run build-web && npm run build-native",
"build-web": "vite build && echo export * from '../src/index'>>dist/index.d.ts",
"build-native": "vite build && echo export * from '../src/index.native'>>dist/index.native.d.ts",
"build": "rimraf dist && vite build && vite build",
"test": "jest",
"lint": "eslint src/**/*.{ts,tsx} && tsc",
"lint-fix": "prettier . --write && eslint --fix src/**/*.{ts,tsx}"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"react-ogl": ["./dist"]
"react-ogl": ["./src"]
}
}
}
12 changes: 10 additions & 2 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import fs from 'fs'
import { defineConfig } from 'vite'

const NATIVE = fs.existsSync(path.resolve(process.cwd(), 'dist'))
const entry = NATIVE ? 'index.native' : 'index'

export default defineConfig({
root: process.argv[2] ? undefined : 'examples',
resolve: {
alias: {
'react-ogl': path.resolve(process.cwd(), 'dist'),
'react-ogl': path.resolve(process.cwd(), 'src'),
},
},
build: {
Expand All @@ -18,7 +19,7 @@ export default defineConfig({
target: 'es2018',
lib: {
formats: ['es'],
entry: NATIVE ? 'src/index.native.ts' : 'src/index.ts',
entry: `src/${entry}.ts`,
fileName: '[name]',
},
rollupOptions: {
Expand All @@ -27,4 +28,11 @@ export default defineConfig({
sourcemapExcludeSources: true,
},
},
plugins: [
{
generateBundle() {
this.emitFile({ type: 'asset', fileName: `${entry}.d.ts`, source: `export * from '../src/${entry}'` })
},
},
],
})

0 comments on commit 97c4690

Please sign in to comment.