threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

rollup.config.mjs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // rollup.config.js
  2. import json from '@rollup/plugin-json';
  3. import resolve from '@rollup/plugin-node-resolve';
  4. import typescript from '@rollup/plugin-typescript';
  5. import packageJson from './package.json' assert {type: 'json'};
  6. import path from 'node:path'
  7. import {fileURLToPath} from 'node:url';
  8. import postcss from 'rollup-plugin-postcss'
  9. import glsl from "rollup-plugin-glsl"
  10. import replace from "@rollup/plugin-replace";
  11. import commonjs from "@rollup/plugin-commonjs";
  12. import license from "rollup-plugin-license";
  13. import terser from "@rollup/plugin-terser";
  14. const __filename = fileURLToPath(import.meta.url);
  15. const __dirname = path.dirname(__filename);
  16. const {name, version, author} = packageJson
  17. const {main, module, browser} = packageJson["clean-package"].replace
  18. const isProduction = process.env.NODE_ENV === 'production'
  19. const settings = {
  20. globals: {},
  21. sourcemap: isProduction
  22. }
  23. export default {
  24. input: './src/index.ts',
  25. output: [
  26. // {
  27. // file: main,
  28. // name: main,
  29. // ...settings,
  30. // format: 'cjs',
  31. // plugins: [
  32. // isProduction && terser()
  33. // ]
  34. // },
  35. {
  36. file: module,
  37. ...settings,
  38. name: name,
  39. // dir: 'dist', // indicate not create a single-file
  40. // preserveModules: true, // indicate not create a single-file
  41. // preserveModulesRoot: 'src', // optional but useful to create a more plain folder structure
  42. format: 'es'
  43. },
  44. isProduction ? {
  45. file: browser,
  46. ...settings,
  47. name: name,
  48. format: 'umd',
  49. plugins: [
  50. isProduction && terser()
  51. ]
  52. } : null,
  53. ],
  54. external: [],
  55. plugins: [
  56. replace({
  57. 'process.env.NODE_ENV': JSON.stringify( 'production' ),
  58. '.css?inline': '.css',
  59. preventAssignment: true,
  60. }),
  61. // replace({
  62. // exclude: 'src/**',
  63. // delimiters: ['', ''],
  64. // values:{
  65. // 'from \'three\'': 'from \'threepipe\'',
  66. // },
  67. // }),
  68. glsl({ // todo: minify glsl.
  69. include: "src/**/*.glsl"
  70. }),
  71. postcss({
  72. extensions: ['.css', '.css?inline'],
  73. modules: false,
  74. autoModules: true, // todo; issues with typescript import css, because inject is false
  75. inject: false,
  76. minimize: isProduction,
  77. // Or with custom options for `postcss-modules`
  78. }),
  79. json(),
  80. resolve({}),
  81. typescript({}),
  82. commonjs({
  83. include: 'node_modules/**',
  84. extensions: ['.js'],
  85. ignoreGlobal: false,
  86. sourceMap: false
  87. }),
  88. license({
  89. banner: `
  90. @license
  91. ${name} v${version}
  92. Copyright 2022<%= moment().format('YYYY') > 2022 ? '-' + moment().format('YYYY') : null %> ${author}
  93. ${packageJson.license} License
  94. See ./dependencies.txt for bundled third-party dependencies and licenses.
  95. `,
  96. thirdParty: {
  97. output: path.join(__dirname, 'dist', 'dependencies.txt'),
  98. includePrivate: true, // Default is false.
  99. },
  100. })
  101. ]
  102. }