rollup.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //import { base64 } from "./util/import-base-64.js"; //add
  2. const fs = require('fs-extra')
  3. const path = require('path')
  4. const babel = require('rollup-plugin-babel');
  5. const { uglify } = require('rollup-plugin-uglify');
  6. const PATH = `./.laser-lib-path`
  7. const buildPaths = [
  8. `build`,
  9. ...fs.existsSync(PATH) ? [fs.readFileSync(PATH).toString()] : []
  10. ]
  11. const builds = []
  12. for (const dir of buildPaths) {
  13. builds.push(
  14. ...[
  15. {
  16. input: 'src/Potree.js',
  17. treeshake: false,
  18. output: {
  19. file: `${dir}/potree/potree.js`,
  20. format: 'umd',
  21. name: 'Potree',
  22. sourcemap: true,
  23. },
  24. //plugins: [//add
  25. // base64({ include: "**/*.wasm" })
  26. //]
  27. }, {
  28. input: 'src/workers/BinaryDecoderWorker.js',
  29. output: {
  30. file: `${dir}/potree/workers/BinaryDecoderWorker.js`,
  31. format: 'es',
  32. name: 'Potree',
  33. sourcemap: false
  34. }
  35. }, {
  36. input: 'src/workers/testWorkers.js',
  37. output: {
  38. file: `${dir}/potree/workers/testWorkers.js`,
  39. format: 'es',
  40. name: 'Potree',
  41. sourcemap: false
  42. }
  43. },{
  44. input: 'src/modules/loader/2.0/DecoderWorker.js',
  45. output: {
  46. file: `${dir}/potree/workers/2.0/DecoderWorker.js`,
  47. format: 'es',
  48. name: 'Potree',
  49. sourcemap: false
  50. }
  51. },{
  52. input: 'src/modules/loader/2.0/DecoderWorker_brotli.js',
  53. output: {
  54. file: `${dir}/potree/workers/2.0/DecoderWorker_brotli.js`,
  55. format: 'es',
  56. name: 'Potree',
  57. sourcemap: false
  58. }
  59. }
  60. ]
  61. )
  62. }
  63. if (process.env.npm_lifecycle_script.includes('production')) {
  64. builds.forEach(item => {
  65. item.output.sourcemap = false
  66. item.plugins = [
  67. [
  68. '@babel/plugin-transform-runtime',
  69. ],
  70. babel({
  71. presets: ['@babel/preset-env'],
  72. exclude: "node_modules/**"
  73. }),
  74. // 压缩代码
  75. uglify()
  76. ]
  77. })
  78. } else {
  79. builds.forEach(item => {
  80. item.plugins = [
  81. babel({
  82. presets: [
  83. [
  84. '@babel/preset-env',
  85. {
  86. targets: {
  87. // 仅转换到支持 ES6 特性的环境
  88. esmodules: true,
  89. browsers: [
  90. "last 2 Chrome versions",
  91. "last 2 Firefox versions",
  92. "last 2 Safari versions",
  93. "last 2 Edge versions"
  94. ]
  95. },
  96. // 禁用将现代代码转换为 ES5 的功能
  97. exclude: ["transform-regenerator", "transform-async-to-generator"]
  98. },
  99. ],
  100. ],
  101. exclude: 'node_modules/**', // 排除 node_modules 目录
  102. }),
  103. ]
  104. })
  105. }
  106. export default builds