36 lines
794 B
TypeScript
36 lines
794 B
TypeScript
|
import path from 'path'
|
||
|
import {build} from 'esbuild'
|
||
|
|
||
|
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.ts')],
|
||
|
bundle: true,
|
||
|
sourcemap: true,
|
||
|
define: definedGlobals,
|
||
|
watch,
|
||
|
platform: 'neutral',
|
||
|
mainFields: ['browser', 'module', 'main'],
|
||
|
target: ['firefox57', 'chrome58'],
|
||
|
conditions: ['browser', 'node'],
|
||
|
}
|
||
|
|
||
|
build({
|
||
|
...esbuildConfig,
|
||
|
outfile: path.join(pathToPackage, 'dist/index.cjs'),
|
||
|
format: 'cjs',
|
||
|
})
|
||
|
|
||
|
build({
|
||
|
...esbuildConfig,
|
||
|
outfile: path.join(pathToPackage, 'dist/index.mjs'),
|
||
|
format: 'esm',
|
||
|
})
|
||
|
}
|
||
|
|
||
|
createBundles(false)
|