Still trying to get cra to play nice with theatre

This commit is contained in:
Aria Minaei 2021-08-07 23:24:37 +02:00
parent 824fdd6843
commit f4f33dcd8d
8 changed files with 88 additions and 62 deletions

View file

@ -1,5 +1,24 @@
import 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',
@ -17,19 +36,20 @@ 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({
...esbuildConfig, ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'), outfile: path.join(pathToPackage, 'dist/index.js'),
format: 'cjs', format: 'cjs',
}) })
build({ // build({
...esbuildConfig, // ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'), // outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm', // format: 'esm',
}) // })
} }
createBundles(false) createBundles(false)

View file

@ -56,7 +56,7 @@ export function usePrism<T>(
return useDerivation(derivation, debugLabel) return useDerivation(derivation, debugLabel)
} }
export const useVal: typeof val = (p, debugLabel?: string) => { export const useVal: typeof val = (p: $IntentionalAny, debugLabel?: string) => {
return usePrism(() => val(p), [p], debugLabel) return usePrism(() => val(p), [p], debugLabel)
} }

View file

@ -1,6 +1,24 @@
import 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',
} }
@ -17,19 +35,20 @@ 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({
...esbuildConfig, ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'), outfile: path.join(pathToPackage, 'dist/index.js'),
format: 'cjs', format: 'cjs',
}) })
build({ // build({
...esbuildConfig, // ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'), // outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm', // format: 'esm',
}) // })
} }
createBundles(false) createBundles(false)

View file

@ -1,10 +1,10 @@
import type {IdentityDerivationProvider} from './Atom' import type {IdentityDerivationProvider} from './Atom'
import type {Pointer} from './pointer'; import type {Pointer} from './pointer'
import pointer from './pointer' import pointer from './pointer'
import type {IBox} from './Box'; import type {IBox} from './Box'
import Box from './Box' import Box from './Box'
import type {$FixMe, $IntentionalAny} from './types' import type {$FixMe, $IntentionalAny} from './types'
import {valueDerivation} from '@theatre/dataverse' import {valueDerivation} from './Atom'
export default class PointerProxy<O extends {}> export default class PointerProxy<O extends {}>
implements IdentityDerivationProvider implements IdentityDerivationProvider

View file

@ -1,7 +1,7 @@
import path from 'path' import * as path from 'path'
import {build} from 'esbuild' import {build} from 'esbuild'
import type {Plugin} from 'esbuild' import type {Plugin} from 'esbuild'
import {writeFileSync} from 'fs' import {mkdirSync, writeFileSync} from 'fs'
const externalPlugin = (patterns: RegExp[]): Plugin => { const externalPlugin = (patterns: RegExp[]): Plugin => {
return { return {
@ -46,7 +46,6 @@ function createBundles(watch: boolean) {
define: {...definedGlobals, 'process.env.NODE_ENV': '"production"'}, define: {...definedGlobals, 'process.env.NODE_ENV': '"production"'},
outfile: path.join(pathToPackage, 'dist/index.production.js'), outfile: path.join(pathToPackage, 'dist/index.production.js'),
format: 'cjs', format: 'cjs',
treeShaking: true,
}) })
build({ build({
@ -56,6 +55,8 @@ function createBundles(watch: boolean) {
format: 'cjs', format: 'cjs',
}) })
mkdirSync(path.join(pathToPackage, 'dist'))
writeFileSync( writeFileSync(
path.join(pathToPackage, 'dist/index.js'), path.join(pathToPackage, 'dist/index.js'),
`module.exports = `module.exports =
@ -65,11 +66,11 @@ function createBundles(watch: boolean) {
{encoding: 'utf-8'}, {encoding: 'utf-8'},
) )
build({ // build({
...esbuildConfig, // ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'), // outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm', // format: 'esm',
}) // })
} }
createBundles(false) createBundles(false)

View file

@ -17,14 +17,7 @@
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"type": "commonjs", "type": "commonjs",
"files": [ "files": [
"dist/index.cjs", "dist/*"
"dist/index.cjs.map",
"dist/index.mjs",
"dist/index.mjs.map",
"dist/index.min.js",
"dist/index.min.js.map",
"dist/index.min.js.LEGAL.txt",
"dist/index.d.ts"
], ],
"scripts": { "scripts": {
"prepublish": "node ../../devEnv/ensurePublishing.js" "prepublish": "node ../../devEnv/ensurePublishing.js"

View file

@ -31,29 +31,29 @@ export function createBundles(watch: boolean) {
build({ build({
...esbuildConfig, ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'), outfile: path.join(pathToPackage, 'dist/index.js'),
format: 'cjs', format: 'cjs',
}) })
build({ // build({
...esbuildConfig, // ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'), // outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm', // format: 'esm',
}) // })
build({ // build({
...esbuildConfig, // ...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.min.js'), // outfile: path.join(pathToPackage, 'dist/index.min.js'),
format: 'iife', // format: 'iife',
external: [], // external: [],
minify: true, // minify: true,
globalName: `Theatre.${which}`, // globalName: `Theatre.${which}`,
legalComments: 'external', // legalComments: 'external',
platform: 'browser', // platform: 'browser',
define: { // define: {
...definedGlobals, // ...definedGlobals,
'process.env.NODE_ENV': JSON.stringify('production'), // 'process.env.NODE_ENV': JSON.stringify('production'),
}, // },
}) // })
} }
} }

View file

@ -16,14 +16,7 @@
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"files": [ "files": [
"dist/index.cjs", "dist/*"
"dist/index.cjs.map",
"dist/index.mjs",
"dist/index.mjs.map",
"dist/index.min.js",
"dist/index.min.js.map",
"dist/index.min.js.LEGAL.txt",
"dist/index.d.ts"
], ],
"scripts": { "scripts": {
"prepublish": "node ../../devEnv/ensurePublishing.js" "prepublish": "node ../../devEnv/ensurePublishing.js"