rollup.config.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. presets: ['@babel/preset-env'],
  60. exclude: "node_modules/**"
  61. }),
  62. // 压缩代码
  63. uglify()
  64. ]
  65. })
  66. } else {
  67. builds.forEach(item => {
  68. item.plugins = [
  69. babel({
  70. presets: [
  71. [
  72. '@babel/preset-env',
  73. {
  74. targets: {
  75. esmodules: true, // 目标是 ES 模块
  76. },
  77. },
  78. ],
  79. ],
  80. exclude: 'node_modules/**', // 排除 node_modules 目录
  81. }),
  82. ]
  83. })
  84. }
  85. export default builds