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 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 = {
global: 'window',
@ -17,19 +36,20 @@ function createBundles(watch: boolean) {
mainFields: ['browser', 'module', 'main'],
target: ['firefox57', 'chrome58'],
conditions: ['browser', 'node'],
plugins: [externalPlugin([/^[\@a-zA-Z]+/])],
}
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'),
outfile: path.join(pathToPackage, 'dist/index.js'),
format: 'cjs',
})
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm',
})
// build({
// ...esbuildConfig,
// outfile: path.join(pathToPackage, 'dist/index.mjs'),
// format: 'esm',
// })
}
createBundles(false)

View file

@ -56,7 +56,7 @@ export function usePrism<T>(
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)
}

View file

@ -1,6 +1,24 @@
import path from 'path'
import * as path from 'path'
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 = {
global: 'window',
}
@ -17,19 +35,20 @@ function createBundles(watch: boolean) {
mainFields: ['browser', 'module', 'main'],
target: ['firefox57', 'chrome58'],
conditions: ['browser', 'node'],
plugins: [externalPlugin([/^[\@a-zA-Z]+/])],
}
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.cjs'),
outfile: path.join(pathToPackage, 'dist/index.js'),
format: 'cjs',
})
build({
...esbuildConfig,
outfile: path.join(pathToPackage, 'dist/index.mjs'),
format: 'esm',
})
// build({
// ...esbuildConfig,
// outfile: path.join(pathToPackage, 'dist/index.mjs'),
// format: 'esm',
// })
}
createBundles(false)

View file

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

View file

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

View file

@ -17,14 +17,7 @@
"types": "dist/index.d.ts",
"type": "commonjs",
"files": [
"dist/index.cjs",
"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"
"dist/*"
],
"scripts": {
"prepublish": "node ../../devEnv/ensurePublishing.js"

View file

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

View file

@ -16,14 +16,7 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/index.cjs",
"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"
"dist/*"
],
"scripts": {
"prepublish": "node ../../devEnv/ensurePublishing.js"