You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* eslint-disable */
  2. const fs = require('fs')
  3. const esbuild = require('esbuild')
  4. const { gzip } = require('zlib')
  5. const name = process.env.npm_package_name || ''
  6. async function main() {
  7. if (fs.existsSync('./dist')) {
  8. fs.rmSync('./dist', { recursive: true }, (e) => {
  9. if (e) {
  10. throw e
  11. }
  12. })
  13. }
  14. try {
  15. esbuild.buildSync({
  16. entryPoints: ['./src/index.ts'],
  17. outdir: 'dist/cjs',
  18. minify: true,
  19. bundle: true,
  20. format: 'cjs',
  21. target: 'es6',
  22. jsxFactory: 'React.createElement',
  23. jsxFragment: 'React.Fragment',
  24. tsconfig: './tsconfig.json',
  25. external: [
  26. 'react',
  27. 'react-dom',
  28. 'tslib',
  29. '@stitches/react',
  30. '@radix-ui/react-alert-dialog',
  31. '@radix-ui/react-checkbox',
  32. '@radix-ui/react-context-menu',
  33. '@radix-ui/react-dropdown-menu',
  34. '@radix-ui/react-icons',
  35. '@radix-ui/react-id',
  36. '@radix-ui/react-radio',
  37. '@radix-ui/react-tooltip',
  38. 'perfect-freehand',
  39. 'rko',
  40. 'react-hotkeys-hook',
  41. 'browser-fs-access',
  42. ],
  43. metafile: true,
  44. })
  45. const esmResult = esbuild.buildSync({
  46. entryPoints: ['./src/index.ts'],
  47. outdir: 'dist/esm',
  48. minify: true,
  49. bundle: true,
  50. format: 'esm',
  51. target: 'es6',
  52. tsconfig: './tsconfig.build.json',
  53. jsxFactory: 'React.createElement',
  54. jsxFragment: 'React.Fragment',
  55. external: [
  56. 'react',
  57. 'react-dom',
  58. 'tslib',
  59. '@stitches/react',
  60. '@radix-ui/react-alert-dialog',
  61. '@radix-ui/react-checkbox',
  62. '@radix-ui/react-context-menu',
  63. '@radix-ui/react-dropdown-menu',
  64. '@radix-ui/react-icons',
  65. '@radix-ui/react-id',
  66. '@radix-ui/react-radio',
  67. '@radix-ui/react-tooltip',
  68. '@tldraw/core',
  69. '@tldraw/vec',
  70. '@tldraw/intersect',
  71. 'perfect-freehand',
  72. 'rko',
  73. 'react-hotkeys-hook',
  74. 'browser-fs-access',
  75. ],
  76. metafile: true,
  77. })
  78. let esmSize = 0
  79. Object.values(esmResult.metafile.outputs).forEach((output) => {
  80. esmSize += output.bytes
  81. })
  82. fs.readFile('./dist/esm/index.js', (_err, data) => {
  83. gzip(data, (_err, result) => {
  84. console.log(
  85. `✔ ${name}: Built package. ${(esmSize / 1000).toFixed(2)}kb (${(
  86. result.length / 1000
  87. ).toFixed(2)}kb minified)`
  88. )
  89. })
  90. })
  91. } catch (e) {
  92. console.log(`× ${name}: Build failed due to an error.`)
  93. console.log(e)
  94. }
  95. }
  96. main()