threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

vite.config.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. }
  16. export default defineConfig({
  17. optimizeDeps: {
  18. exclude: ['uiconfig.js', 'ts-browser-helpers'],
  19. },
  20. base: '',
  21. // define: {
  22. // 'process.env': process.env
  23. // },
  24. build: {
  25. sourcemap: true,
  26. minify: false,
  27. cssMinify: isProd,
  28. cssCodeSplit: false,
  29. watch: !isProd ? {
  30. buildDelay: 1000,
  31. } : null,
  32. lib: {
  33. entry: 'src/index.ts',
  34. formats: isProd ? ['es', 'umd'] : ['es'],
  35. name: name,
  36. fileName: (format) => (format === 'umd' ? main : module).replace('dist/', ''),
  37. },
  38. outDir: 'dist',
  39. emptyOutDir: isProd,
  40. commonjsOptions: {
  41. exclude: [/uiconfig.js/, /ts-browser-helpers/],
  42. },
  43. rollupOptions: {
  44. output: {
  45. // inlineDynamicImports: false,
  46. globals,
  47. },
  48. external: Object.keys(globals),
  49. },
  50. },
  51. plugins: [
  52. isProd ? dts({tsconfigPath: './tsconfig.json'}) : null,
  53. replace({
  54. 'from \'three\'': 'from \'threepipe\'',
  55. // 'from \'three/examples/jsm/.*\'': 'from \'threepipe\'', // todo regex doesnt work...
  56. 'from \'three/examples/jsm/loaders/GLTFLoader.js\'': 'from \'threepipe\'',
  57. 'from \'three/examples/jsm/postprocessing/Pass.js\'': 'from \'threepipe\'',
  58. 'from \'three/examples/jsm/utils/BufferGeometryUtils.js\'': 'from \'threepipe\'',
  59. delimiters: ['', ''],
  60. preventAssignment: true,
  61. }),
  62. replace({ // this is added to throw an error, in that case, add it to above
  63. 'from \'three/': 'from \'unknown/',
  64. delimiters: ['', ''],
  65. preventAssignment: true,
  66. }),
  67. replace({
  68. 'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
  69. preventAssignment: true,
  70. }),
  71. glsl({ // todo: minify glsl.
  72. include: 'src/**/*.glsl',
  73. }),
  74. json(),
  75. // postcss({
  76. // modules: false,
  77. // autoModules: true, // todo; issues with typescript import css, because inject is false
  78. // inject: false,
  79. // minimize: isProduction,
  80. // // Or with custom options for `postcss-modules`
  81. // }),
  82. license({
  83. banner: `
  84. @license
  85. ${name} v${version}
  86. Copyright 2022<%= moment().format('YYYY') > 2022 ? '-' + moment().format('YYYY') : null %> ${author}
  87. ${packageJson.license} License
  88. See ./dependencies.txt for any bundled third-party dependencies and licenses.
  89. `,
  90. thirdParty: {
  91. output: path.join(__dirname, 'dist', 'dependencies.txt'),
  92. includePrivate: true, // Default is false.
  93. },
  94. }),
  95. ],
  96. })