Fix various issues with the build system (#129)
* Fix react-icons breaking in CRA 5 for some reason * Replace fuzzysort with fuzzy so we don't break Webpack Webpack messes up esbuild’s internal modules if the inlined module is an AMD module. Check any new dep you add if it is an AMD module. * Inline dataverse deps. Mainly because the CJS build consuming the ESM lodash-es broke some bundlers. * react-icons fix nr 2 * Stop eslint breaking in CRA 5 * Update r3f-cra example to CRA 5 and fix double-bundling react & co * Fix r3f tree-shaking and switch to ESM only output * Make r3f example shake studio and its extension in prod * Examples have separate and wildly differing build setups so remove them from the pre-commit hook linting * Update out-of-date yarn.lock
This commit is contained in:
parent
f2089302d5
commit
39da042edc
18 changed files with 6066 additions and 218 deletions
5
examples/r3f-cra/.eslintrc.json
Normal file
5
examples/r3f-cra/.eslintrc.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"react-app"
|
||||||
|
]
|
||||||
|
}
|
|
@ -7,15 +7,12 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@react-three/drei": "^7.2.2",
|
"@react-three/drei": "^7.2.2",
|
||||||
"@react-three/fiber": "^7.0.6",
|
|
||||||
"@testing-library/jest-dom": "^5.11.4",
|
"@testing-library/jest-dom": "^5.11.4",
|
||||||
"@testing-library/react": "^11.1.0",
|
"@testing-library/react": "^11.1.0",
|
||||||
"@testing-library/user-event": "^12.1.10",
|
"@testing-library/user-event": "^12.1.10",
|
||||||
"@theatre/core": "workspace:*",
|
"@theatre/core": "workspace:*",
|
||||||
"@theatre/r3f": "workspace:*",
|
"@theatre/r3f": "workspace:*",
|
||||||
"react": "^17.0.2",
|
"react-scripts": "^5.0.1",
|
||||||
"react-dom": "^17.0.2",
|
|
||||||
"react-scripts": "4.0.3",
|
|
||||||
"three": "^0.130.1",
|
"three": "^0.130.1",
|
||||||
"web-vitals": "^1.0.1"
|
"web-vitals": "^1.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,11 +4,13 @@ import {useState, useEffect, useRef} from 'react'
|
||||||
import {useFrame, Canvas} from '@react-three/fiber'
|
import {useFrame, Canvas} from '@react-three/fiber'
|
||||||
import {Shadow, softShadows} from '@react-three/drei'
|
import {Shadow, softShadows} from '@react-three/drei'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {editable as e, SheetProvider, extension} from '@theatre/r3f'
|
|
||||||
import studio from '@theatre/studio'
|
import studio from '@theatre/studio'
|
||||||
|
import {editable as e, SheetProvider, extension} from '@theatre/r3f'
|
||||||
|
|
||||||
studio.extend(extension)
|
if (process.env.NODE_ENV === 'development') {
|
||||||
studio.initialize()
|
studio.extend(extension)
|
||||||
|
studio.initialize()
|
||||||
|
}
|
||||||
|
|
||||||
// Soft shadows are expensive, comment and refresh when it's too slow
|
// Soft shadows are expensive, comment and refresh when it's too slow
|
||||||
softShadows()
|
softShadows()
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"lint:all": "eslint . --ext ts,tsx --ignore-path=.gitignore --rulesdir ./devEnv/eslint/rules"
|
"lint:all": "eslint . --ext ts,tsx --ignore-path=.gitignore --rulesdir ./devEnv/eslint/rules"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"**/*.(t|j)s?(x)": [
|
"theatre/**/*.(t|j)s?(x)": [
|
||||||
"eslint --rulesdir ./devEnv/eslint/rules --fix",
|
"eslint --rulesdir ./devEnv/eslint/rules --fix",
|
||||||
"prettier --write"
|
"prettier --write"
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {build} from 'esbuild'
|
import {build} from 'esbuild'
|
||||||
import type {Plugin} from 'esbuild'
|
|
||||||
|
|
||||||
const externalPlugin = (patterns: RegExp[]): Plugin => {
|
|
||||||
return {
|
|
||||||
name: `external`,
|
|
||||||
|
|
||||||
setup(build) {
|
|
||||||
build.onResolve({filter: /.*/}, (args) => {
|
|
||||||
const external = patterns.some((p) => {
|
|
||||||
return p.test(args.path)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (external) {
|
|
||||||
return {path: args.path, external}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const definedGlobals = {
|
const definedGlobals = {
|
||||||
global: 'window',
|
global: 'window',
|
||||||
}
|
}
|
||||||
|
@ -35,7 +17,6 @@ function createBundles(watch: boolean) {
|
||||||
mainFields: ['browser', 'module', 'main'],
|
mainFields: ['browser', 'module', 'main'],
|
||||||
target: ['firefox57', 'chrome58'],
|
target: ['firefox57', 'chrome58'],
|
||||||
conditions: ['browser', 'node'],
|
conditions: ['browser', 'node'],
|
||||||
plugins: [externalPlugin([/^[\@a-zA-Z]+/])],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build({
|
build({
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
import * as path from 'path'
|
|
||||||
import {build} from 'esbuild'
|
|
||||||
import type {Plugin} from 'esbuild'
|
|
||||||
import {existsSync, mkdirSync, writeFileSync} from 'fs'
|
|
||||||
|
|
||||||
const externalPlugin = (patterns: RegExp[]): Plugin => {
|
|
||||||
return {
|
|
||||||
name: `external`,
|
|
||||||
|
|
||||||
setup(build) {
|
|
||||||
build.onResolve({filter: /.*/}, (args) => {
|
|
||||||
const external = patterns.some((p) => {
|
|
||||||
return p.test(args.path)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (external) {
|
|
||||||
return {path: args.path, external}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const definedGlobals = {
|
|
||||||
global: 'window',
|
|
||||||
}
|
|
||||||
|
|
||||||
function createBundles(watch: boolean) {
|
|
||||||
const pathToPackage = path.join(__dirname, '../')
|
|
||||||
const esbuildConfig: Parameters<typeof build>[0] = {
|
|
||||||
entryPoints: [path.join(pathToPackage, 'src/index.tsx')],
|
|
||||||
bundle: true,
|
|
||||||
sourcemap: true,
|
|
||||||
define: definedGlobals,
|
|
||||||
watch,
|
|
||||||
platform: 'neutral',
|
|
||||||
mainFields: ['browser', 'module', 'main'],
|
|
||||||
target: ['firefox57', 'chrome58'],
|
|
||||||
conditions: ['browser', 'node'],
|
|
||||||
// every dependency is considered external
|
|
||||||
plugins: [externalPlugin([/^[\@a-zA-Z]+/])],
|
|
||||||
}
|
|
||||||
|
|
||||||
build({
|
|
||||||
...esbuildConfig,
|
|
||||||
define: {...definedGlobals, 'process.env.NODE_ENV': '"production"'},
|
|
||||||
outfile: path.join(pathToPackage, 'dist/index.production.js'),
|
|
||||||
format: 'cjs',
|
|
||||||
})
|
|
||||||
|
|
||||||
build({
|
|
||||||
...esbuildConfig,
|
|
||||||
define: {...definedGlobals, 'process.env.NODE_ENV': '"development"'},
|
|
||||||
outfile: path.join(pathToPackage, 'dist/index.development.js'),
|
|
||||||
format: 'cjs',
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!existsSync(path.join(pathToPackage, 'dist')))
|
|
||||||
mkdirSync(path.join(pathToPackage, 'dist'))
|
|
||||||
|
|
||||||
writeFileSync(
|
|
||||||
path.join(pathToPackage, 'dist/index.js'),
|
|
||||||
`module.exports =
|
|
||||||
process.env.NODE_ENV === "production"
|
|
||||||
? require("./index.production.js")
|
|
||||||
: require("./index.development.js")`,
|
|
||||||
{encoding: 'utf-8'},
|
|
||||||
)
|
|
||||||
|
|
||||||
build({
|
|
||||||
...esbuildConfig,
|
|
||||||
outfile: path.join(pathToPackage, 'dist/index.mjs'),
|
|
||||||
format: 'esm',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
createBundles(false)
|
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,9 +19,9 @@
|
||||||
"url": "https://github.com/AriaMinaei/theatre",
|
"url": "https://github.com/AriaMinaei/theatre",
|
||||||
"directory": "packages/r3f"
|
"directory": "packages/r3f"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
"main": "dist/esm/index.js",
|
||||||
"module": "dist/index.mjs",
|
"module": "dist/esm/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/esm/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"files": [
|
"files": [
|
||||||
"dist/**/*"
|
"dist/**/*"
|
||||||
|
@ -29,9 +29,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepack": "yarn run build",
|
"prepack": "yarn run build",
|
||||||
"typecheck": "yarn run build",
|
"typecheck": "yarn run build",
|
||||||
"build": "run-s build:ts build:js",
|
"build": "tsc --build ./tsconfig.json",
|
||||||
"build:ts": "tsc --build ./tsconfig.json",
|
|
||||||
"build:js": "node -r esbuild-register ./devEnv/build.ts",
|
|
||||||
"prepublish": "yarn run build"
|
"prepublish": "yarn run build"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -12,14 +12,9 @@ import {useHelper, Sphere, Html} from '@react-three/drei'
|
||||||
import type {EditableType} from '../store'
|
import type {EditableType} from '../store'
|
||||||
import {useEditorStore} from '../store'
|
import {useEditorStore} from '../store'
|
||||||
import shallow from 'zustand/shallow'
|
import shallow from 'zustand/shallow'
|
||||||
import {
|
import {GiCube, GiLightBulb, GiLightProjector} from 'react-icons/gi'
|
||||||
BiSun,
|
import {BsCameraVideoFill, BsFillCollectionFill} from 'react-icons/bs'
|
||||||
BsCameraVideoFill,
|
import {BiSun} from 'react-icons/bi'
|
||||||
BsFillCollectionFill,
|
|
||||||
GiCube,
|
|
||||||
GiLightBulb,
|
|
||||||
GiLightProjector,
|
|
||||||
} from 'react-icons/all'
|
|
||||||
import type {IconType} from 'react-icons'
|
import type {IconType} from 'react-icons'
|
||||||
import studio from '@theatre/studio'
|
import studio from '@theatre/studio'
|
||||||
import {useSelected} from './useSelected'
|
import {useSelected} from './useSelected'
|
||||||
|
|
|
@ -9,7 +9,7 @@ import ProxyManager from './ProxyManager'
|
||||||
import studio, {ToolbarIconButton} from '@theatre/studio'
|
import studio, {ToolbarIconButton} from '@theatre/studio'
|
||||||
import {useVal} from '@theatre/react'
|
import {useVal} from '@theatre/react'
|
||||||
import styled, {createGlobalStyle, StyleSheetManager} from 'styled-components'
|
import styled, {createGlobalStyle, StyleSheetManager} from 'styled-components'
|
||||||
import {IoCameraReverseOutline} from 'react-icons/all'
|
import {IoCameraReverseOutline} from 'react-icons/io5'
|
||||||
import type {ISheet} from '@theatre/core'
|
import type {ISheet} from '@theatre/core'
|
||||||
import useSnapshotEditorCamera from './useSnapshotEditorCamera'
|
import useSnapshotEditorCamera from './useSnapshotEditorCamera'
|
||||||
import {getEditorSheet, getEditorSheetObject} from './editorStuff'
|
import {getEditorSheet, getEditorSheetObject} from './editorStuff'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import type {VFC} from 'react'
|
import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {IoCameraOutline} from 'react-icons/all'
|
import {IoCameraOutline} from 'react-icons/io5'
|
||||||
import studio, {ToolbarIconButton} from '@theatre/studio'
|
import studio, {ToolbarIconButton} from '@theatre/studio'
|
||||||
import {useVal} from '@theatre/react'
|
import {useVal} from '@theatre/react'
|
||||||
import TransformControlsModeSelect from './TransformControlsModeSelect'
|
import TransformControlsModeSelect from './TransformControlsModeSelect'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {ToolbarSwitchSelect} from '@theatre/studio'
|
import {ToolbarSwitchSelect} from '@theatre/studio'
|
||||||
import type {VFC} from 'react'
|
import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {GiClockwiseRotation, GiMove, GiResize} from 'react-icons/all'
|
import {GiClockwiseRotation, GiMove, GiResize} from 'react-icons/gi'
|
||||||
import type {TransformControlsMode} from '../../store'
|
import type {TransformControlsMode} from '../../store'
|
||||||
|
|
||||||
export interface TransformControlsModeSelectProps {
|
export interface TransformControlsModeSelectProps {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import type {VFC} from 'react'
|
import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type {TransformControlsSpace} from '../../store'
|
import type {TransformControlsSpace} from '../../store'
|
||||||
import {BiCube, BiGlobe} from 'react-icons/all'
|
import {BiCube, BiGlobe} from 'react-icons/bi'
|
||||||
import {ToolbarSwitchSelect} from '@theatre/studio'
|
import {ToolbarSwitchSelect} from '@theatre/studio'
|
||||||
|
|
||||||
export interface TransformControlsSpaceSelectProps {
|
export interface TransformControlsSpaceSelectProps {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import type {VFC} from 'react'
|
import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type {ViewportShading} from '../../store'
|
import type {ViewportShading} from '../../store'
|
||||||
import {FaCube, GiCube, GiIceCube, BiCube} from 'react-icons/all'
|
import {FaCube} from 'react-icons/fa'
|
||||||
|
import {GiCube, GiIceCube} from 'react-icons/gi'
|
||||||
|
import {BiCube} from 'react-icons/bi'
|
||||||
import {ToolbarSwitchSelect} from '@theatre/studio'
|
import {ToolbarSwitchSelect} from '@theatre/studio'
|
||||||
|
|
||||||
export interface ViewportShadingSelectProps {
|
export interface ViewportShadingSelectProps {
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
{
|
{
|
||||||
"extends": "../../tsconfig.base.json",
|
"extends": "../../tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "dist",
|
"outDir": "dist/esm",
|
||||||
"lib": ["ESNext", "DOM"],
|
"lib": ["ESNext", "DOM"],
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"types": ["jest", "node"],
|
"types": ["jest", "node"],
|
||||||
"emitDeclarationOnly": true,
|
|
||||||
"composite": true
|
"composite": true
|
||||||
},
|
},
|
||||||
"references": [{"path": "../../theatre"}],
|
"references": [{"path": "../../theatre"}],
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"fuzzysort": "^1.1.4"
|
"fuzzy": "^0.1.3"
|
||||||
},
|
},
|
||||||
"//": "Add packages here to have them bundled with studio, otherwise add them in the package.json of either studio or core, and they'll be treated as their externals."
|
"//": "Add packages here to have them bundled with studio, otherwise add them in the package.json of either studio or core, and they'll be treated as their externals."
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import type {Pointer} from '@theatre/dataverse'
|
||||||
import {val} from '@theatre/dataverse'
|
import {val} from '@theatre/dataverse'
|
||||||
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react'
|
import React, {useLayoutEffect, useMemo, useRef, useState} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import fuzzySort from 'fuzzysort'
|
import fuzzy from 'fuzzy'
|
||||||
import type {SequenceEditorPanelLayout} from '@theatre/studio/panels/SequenceEditorPanel/layout/layout'
|
import type {SequenceEditorPanelLayout} from '@theatre/studio/panels/SequenceEditorPanel/layout/layout'
|
||||||
import getStudio from '@theatre/studio/getStudio'
|
import getStudio from '@theatre/studio/getStudio'
|
||||||
import type {CommitOrDiscard} from '@theatre/studio/StudioStore/StudioStore'
|
import type {CommitOrDiscard} from '@theatre/studio/StudioStore/StudioStore'
|
||||||
|
@ -132,10 +132,12 @@ const CurveEditorPopover: React.FC<
|
||||||
|
|
||||||
const presetSearchResults = useMemo(
|
const presetSearchResults = useMemo(
|
||||||
() =>
|
() =>
|
||||||
fuzzySort.go(filter, presets, {
|
fuzzy.filter(filter, presets, {
|
||||||
key: 'label',
|
extract: (el) => el.label,
|
||||||
allowTypo: false,
|
pre: '<b>',
|
||||||
|
post: '</b>',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[filter],
|
[filter],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -145,7 +147,7 @@ const CurveEditorPopover: React.FC<
|
||||||
|
|
||||||
const displayedPresets = useMemo(
|
const displayedPresets = useMemo(
|
||||||
() =>
|
() =>
|
||||||
useQuery ? presetSearchResults.map((result) => result.obj) : presets,
|
useQuery ? presetSearchResults.map((result) => result.original) : presets,
|
||||||
[presetSearchResults, useQuery],
|
[presetSearchResults, useQuery],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -199,7 +201,7 @@ const CurveEditorPopover: React.FC<
|
||||||
}
|
}
|
||||||
const args =
|
const args =
|
||||||
cssCubicBezierArgsToHandles(newCurve) ??
|
cssCubicBezierArgsToHandles(newCurve) ??
|
||||||
cssCubicBezierArgsToHandles(presetSearchResults[0].obj.value)
|
cssCubicBezierArgsToHandles(presetSearchResults[0].original.value)
|
||||||
|
|
||||||
if (!args) {
|
if (!args) {
|
||||||
return
|
return
|
||||||
|
@ -409,9 +411,7 @@ const CurveEditorPopover: React.FC<
|
||||||
{useQuery ? (
|
{useQuery ? (
|
||||||
<span
|
<span
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: fuzzySort.highlight(
|
__html: presetSearchResults[index].string,
|
||||||
presetSearchResults[index] as any,
|
|
||||||
)!,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|
Loading…
Reference in a new issue