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,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)