UNPKG

wix-style-react

Version:
51 lines (45 loc) 1.28 kB
import { build } from 'esbuild'; import fs from 'fs'; import { readFile } from 'fs/promises'; const outdir = '__tests__/bundle-size'; // Read all components const componentsToBundle = JSON.parse( await readFile(new URL('../.wuf/components.json', import.meta.url)), ); const components = Object.keys(componentsToBundle).reduce((accu, comp) => { return [ ...accu, `${componentsToBundle[comp].path.replace( 'src/', './dist/es/src/', )}/${comp}.js`, ]; }, []); // Build const result = await build({ entryPoints: components, loader: { '.js': 'jsx' }, jsx: 'transform', metafile: true, bundle: true, external: [ 'react', 'react-dom', 'prop-types', 'react-is', 'tslib', '*.css', // TODO: find better way to crawl all components, not only those that are exposed to consumers ...components, './dist/es/src/BaseModalLayout/BaseModalLayout.js', './dist/es/src/Transition/Toggle/Toggle.js', './dist/es/src/common/Ellipsis/*', './dist/es/src/common/PropTypes/*', ], outdir, logOverride: { 'ignored-bare-import': 'error', }, }); // Produce an analysis json to be used here: https://esbuild.github.io/analyze/ fs.writeFileSync(`${outdir}/meta.json`, JSON.stringify(result.metafile));