threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {defineConfig} from 'vite'
  2. import json from '@rollup/plugin-json';
  3. import dts from 'vite-plugin-dts'
  4. import packageJson from './package.json';
  5. import license from 'rollup-plugin-license';
  6. import replace from '@rollup/plugin-replace';
  7. import glsl from 'rollup-plugin-glsl';
  8. import path from 'node:path';
  9. const isProd = process.env.NODE_ENV === 'production'
  10. const { name, version, author } = packageJson
  11. const {main, module, browser} = packageJson
  12. const globals = {
  13. 'three': 'threepipe', // just incase someone uses three
  14. 'threepipe': 'threepipe',
  15. // '@threepipe/plugin-tweakpane': '@threepipe/plugin-tweakpane',
  16. }
  17. export default defineConfig({
  18. optimizeDeps: {
  19. exclude: ['uiconfig.js', 'ts-browser-helpers'],
  20. },
  21. base: '',
  22. // define: {
  23. // 'process.env': process.env
  24. // },
  25. build: {
  26. sourcemap: true,
  27. minify: false,
  28. cssMinify: isProd,
  29. cssCodeSplit: false,
  30. watch: !isProd ? {
  31. buildDelay: 1000,
  32. } : null,
  33. lib: {
  34. entry: 'src/index.ts',
  35. formats: isProd ? ['es', 'umd'] : ['es'],
  36. name: name,
  37. fileName: (format) => (format === 'umd' ? main : module).replace('dist/', ''),
  38. },
  39. outDir: 'dist',
  40. emptyOutDir: isProd,
  41. commonjsOptions: {
  42. exclude: [/uiconfig.js/, /ts-browser-helpers/],
  43. },
  44. rollupOptions: {
  45. output: {
  46. // inlineDynamicImports: false,
  47. globals,
  48. },
  49. external: Object.keys(globals),
  50. },
  51. },
  52. plugins: [
  53. isProd ? dts({tsconfigPath: './tsconfig.json'}) : null,
  54. replace({
  55. 'from \'three\'': 'from \'threepipe\'',
  56. // 'from \'three/examples/jsm/.*\'': 'from \'threepipe\'', // todo regex doesnt work...
  57. 'from \'three/examples/jsm/postprocessing/Pass.js\'': 'from \'threepipe\'',
  58. delimiters: ['', ''],
  59. }),
  60. replace({
  61. 'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
  62. preventAssignment: true,
  63. }),
  64. glsl({ // todo: minify glsl.
  65. include: 'src/**/*.glsl',
  66. }),
  67. json(),
  68. // postcss({
  69. // modules: false,
  70. // autoModules: true, // todo; issues with typescript import css, because inject is false
  71. // inject: false,
  72. // minimize: isProduction,
  73. // // Or with custom options for `postcss-modules`
  74. // }),
  75. license({
  76. banner: `
  77. @license
  78. ${name} v${version}
  79. Copyright 2022<%= moment().format('YYYY') > 2022 ? '-' + moment().format('YYYY') : null %> ${author}
  80. ${packageJson.license} License
  81. See ./dependencies.txt for any bundled third-party dependencies and licenses.
  82. `,
  83. thirdParty: {
  84. output: path.join(__dirname, 'dist', 'dependencies.txt'),
  85. includePrivate: true, // Default is false.
  86. },
  87. }),
  88. ],
  89. })