rollup.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const fs = require('fs-extra')
  2. const path = require('path')
  3. const babel = require('rollup-plugin-babel');
  4. const { uglify } = require('rollup-plugin-uglify');
  5. const PATH = `./.laser-lib-path`
  6. const buildPaths = [
  7. `build`,
  8. ...fs.existsSync(PATH) ? [fs.readFileSync(PATH).toString()] : []
  9. ]
  10. const builds = []
  11. for (const dir of buildPaths) {
  12. builds.push(
  13. ...[
  14. {
  15. input: 'src/Potree.js',
  16. treeshake: false,
  17. output: {
  18. file: `${dir}/potree/potree.js`,
  19. format: 'umd',
  20. name: 'Potree',
  21. sourcemap: true,
  22. }
  23. }, {
  24. input: 'src/workers/BinaryDecoderWorker.js',
  25. output: {
  26. file: `${dir}/potree/workers/BinaryDecoderWorker.js`,
  27. format: 'es',
  28. name: 'Potree',
  29. sourcemap: false
  30. }
  31. },{
  32. input: 'src/modules/loader/2.0/DecoderWorker.js',
  33. output: {
  34. file: `${dir}/potree/workers/2.0/DecoderWorker.js`,
  35. format: 'es',
  36. name: 'Potree',
  37. sourcemap: false
  38. }
  39. },{
  40. input: 'src/modules/loader/2.0/DecoderWorker_brotli.js',
  41. output: {
  42. file: `${dir}/potree/workers/2.0/DecoderWorker_brotli.js`,
  43. format: 'es',
  44. name: 'Potree',
  45. sourcemap: false
  46. }
  47. }
  48. ]
  49. )
  50. }
  51. if (process.env.npm_lifecycle_script.includes('production')) {
  52. builds.forEach(item => {
  53. item.output.sourcemap = false
  54. item.plugins = [
  55. [
  56. '@babel/plugin-transform-runtime',
  57. ],
  58. babel({
  59. exclude: "node_modules/**"
  60. }),
  61. // 压缩代码
  62. uglify()
  63. ]
  64. })
  65. }
  66. export default builds