Skip to content

Commit

Permalink
fix: enable tree-shaking in webpack, sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Jul 25, 2022
1 parent 3745223 commit 4d89853
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"env": {
"browser": true,
"es6": true,
"node": true,
"jest": true
},
"plugins": ["@typescript-eslint", "react", "react-hooks", "import"],
Expand Down
4 changes: 0 additions & 4 deletions examples/tsconfig.json

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"react-native": "./dist/index.native.mjs",
"sideEffects": false,
"files": [
"dist/*"
"dist/*",
"src/*"
],
"devDependencies": {
"@swc/cli": "^0.1.57",
Expand Down Expand Up @@ -83,9 +84,9 @@
},
"scripts": {
"dev": "vite",
"build": "rimraf dist && vite build && vite build && tsc",
"build": "rimraf dist && vite build && vite build",
"test": "jest",
"lint": "eslint src/**/*.{ts,tsx}",
"lint": "eslint src/**/*.{ts,tsx} && tsc",
"lint-fix": "prettier . --write && eslint --fix src/**/*.{ts,tsx}"
}
}
2 changes: 1 addition & 1 deletion tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('renderer', () => {
it('should update program uniforms reactively', async () => {
const mesh = React.createRef<OGL.Mesh>()

const Test = ({ value }) => (
const Test = ({ value }: { value: any }) => (
<mesh ref={mesh}>
<box />
<normalProgram uniforms={{ uniform: { value } }} />
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jest.mock('react-native', () => ({
jest.mock('react-native/Libraries/Pressability/Pressability.js', () => ({}))
jest.mock('@expo/browser-polyfill', () => ({}))
jest.mock('expo-gl', () => ({
GLView: ({ onContextCreate }) => {
GLView: ({ onContextCreate }: { onContextCreate: any }) => {
React.useLayoutEffect(() => {
const gl = new WebGLRenderingContext({ width: 1280, height: 800 } as HTMLCanvasElement)
onContextCreate(gl)
Expand Down
6 changes: 2 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
"pretty": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
"emitDeclarationOnly": true,
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"react-ogl": ["./src"]
}
},
"include": ["src/**/*"]
}
}
20 changes: 15 additions & 5 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@ import path from 'path'
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: 'examples',
root: process.argv[2] ? undefined : 'examples',
resolve: {
alias: {
'react-ogl': path.resolve(process.cwd(), 'src'),
},
},
build: {
minify: false,
outDir: path.resolve(process.cwd(), 'dist'),
emptyOutDir: false,
sourcemap: true,
target: 'es2018',
lib: {
formats: ['es'],
entry: fs.existsSync(path.resolve(process.cwd(), 'dist'))
? path.resolve(process.cwd(), 'src/index.native.ts')
: path.resolve(process.cwd(), 'src/index.ts'),
entry: `src/${entry}.ts`,
fileName: '[name]',
},
rollupOptions: {
external: (id) => !id.startsWith('.') && !path.isAbsolute(id),
preserveModules: !NATIVE,
sourcemapExcludeSources: true,
},
},
plugins: [
{
generateBundle() {
this.emitFile({ type: 'asset', fileName: `${entry}.d.ts`, source: `export * from '../src/${entry}'` })
},
},
],
})

0 comments on commit 4d89853

Please sign in to comment.