rollup.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import typescript from 'rollup-plugin-typescript2';
  2. import externals from 'rollup-plugin-node-externals';
  3. import { nodeResolve } from '@rollup/plugin-node-resolve';
  4. import alias from '@rollup/plugin-alias';
  5. import eslint from '@rbnlffl/rollup-plugin-eslint';
  6. import { terser } from 'rollup-plugin-terser';
  7. import { getOcularConfig } from 'ocular-dev-tools';
  8. const { NODE_ENV } = process.env;
  9. const input = 'src/index.ts';
  10. const name = 'ThreeLoader3DTiles';
  11. const sourcemap = true;
  12. // If developing along with loaders.gl, use the source instead of the package from npm
  13. const commonPlugins = (env) => {
  14. const plugins = [
  15. externals(),
  16. alias({
  17. entries: process.env.LOADERS_GL_SRC ?
  18. Object.entries(
  19. getOcularConfig({root: process.env.LOADERS_GL_SRC}).aliases
  20. )
  21. .map(
  22. ([key, value], i) => ({
  23. find: key,
  24. replacement: value
  25. })
  26. )
  27. : []
  28. }),
  29. addSyntheticNamedExportsToSkippedNodeImports(),
  30. nodeResolve({
  31. extensions: ['.js', '.ts'],
  32. browser: true
  33. }),
  34. eslint({filterExclude: ['node_modules/**']}),
  35. typescript({
  36. tsconfigDefaults: {
  37. compilerOptions: {
  38. paths: process.env.LOADERS_GL_SRC ?
  39. Object.fromEntries(
  40. Object.entries(
  41. getOcularConfig({root: process.env.LOADERS_GL_SRC}).aliases
  42. )
  43. .map(
  44. ([key, value], i) => [key, [value]]
  45. )
  46. )
  47. : {}
  48. }
  49. }
  50. })
  51. ];
  52. if (env === 'production') {
  53. plugins.push(terser());
  54. }
  55. return plugins;
  56. };
  57. const addSyntheticNamedExportsToSkippedNodeImports = () => ({
  58. load: (importee) => {
  59. if (importee === '\u0000node-resolve:empty.js') {
  60. return {code: 'export default {};', syntheticNamedExports: true};
  61. } else {
  62. return null;
  63. }
  64. }
  65. });
  66. const umdConfig = (env) => ({
  67. input,
  68. output: {
  69. file: `dist/three-loader-3dtiles${env == 'production' ? '.min' : ''}.js`,
  70. format: 'umd',
  71. name,
  72. sourcemap,
  73. globals: {
  74. three: 'THREE',
  75. 'three/examples/jsm/loaders/GLTFLoader.js' : 'THREE',
  76. 'three/examples/jsm/loaders/DRACOLoader.js' : 'THREE',
  77. 'three/examples/jsm/loaders/KTX2Loader.js' : 'THREE'
  78. },
  79. },
  80. external: [
  81. 'three',
  82. 'three/examples/jsm/loaders/GLTFLoader.js',
  83. 'three/examples/jsm/loaders/DRACOLoader.js',
  84. 'three/examples/jsm/loaders/KTX2Loader.js'
  85. ],
  86. plugins: [...commonPlugins(env)],
  87. })
  88. const esmConfig = (env) => ({
  89. input,
  90. output: {
  91. file: `dist/three-loader-3dtiles.esm${env == 'production' ? '.min' : ''}.js`,
  92. format: 'es',
  93. name,
  94. sourcemap,
  95. },
  96. plugins: [...commonPlugins(env)]
  97. })
  98. const config = [esmConfig('development'), umdConfig('development')];
  99. if (NODE_ENV === 'production') {
  100. config.push(esmConfig('production'), umdConfig('production'))
  101. }
  102. export default config;