threepipe
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

vite.config.js 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 && main !== module ? ['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. delimiters: ['', ''],
  57. preventAssignment: true,
  58. }),
  59. replace({
  60. 'process.env.NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
  61. preventAssignment: true,
  62. }),
  63. glsl({ // todo: minify glsl.
  64. include: 'src/**/*.glsl',
  65. }),
  66. json(),
  67. // postcss({
  68. // modules: false,
  69. // autoModules: true, // todo; issues with typescript import css, because inject is false
  70. // inject: false,
  71. // minimize: isProduction,
  72. // // Or with custom options for `postcss-modules`
  73. // }),
  74. license({
  75. banner: `
  76. @license
  77. ${name} v${version}
  78. Copyright 2022<%= moment().format('YYYY') > 2022 ? '-' + moment().format('YYYY') : null %> ${author}
  79. ${packageJson.license} License
  80. See ./dependencies.txt for any bundled third-party dependencies and licenses.
  81. `,
  82. thirdParty: {
  83. output: path.join(__dirname, 'dist', 'dependencies.txt'),
  84. includePrivate: true, // Default is false.
  85. },
  86. }),
  87. ],
  88. })