您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

build.mjs 1021B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* eslint-disable */
  2. import fs from 'fs'
  3. import esbuild from 'esbuild'
  4. import { createRequire } from 'module'
  5. const pkg = createRequire(import.meta.url)('../package.json')
  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.tsx'],
  17. outdir: 'dist',
  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. define: {
  26. 'process.env.NODE_ENV': '"production"',
  27. },
  28. metafile: false,
  29. sourcemap: false,
  30. })
  31. fs.copyFile('./src/index.html', './dist/index.html', (err) => {
  32. if (err) throw err
  33. })
  34. console.log(`✔ ${pkg.name}: Build completed.`)
  35. } catch (e) {
  36. console.log(`× ${pkg.name}: Build failed due to an error.`)
  37. console.log(e)
  38. }
  39. }
  40. main()