rollup.config.mjs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import nodeResolve from '@rollup/plugin-node-resolve';
  2. import commonjs from '@rollup/plugin-commonjs';
  3. import babel from '@rollup/plugin-babel';
  4. import replace from '@rollup/plugin-replace';
  5. import terser from '@rollup/plugin-terser';
  6. import license from 'rollup-plugin-license';
  7. import path from 'path';
  8. import { fileURLToPath } from 'url';
  9. import { dirname } from 'path';
  10. const __filename = fileURLToPath(import.meta.url);
  11. const __dirname = dirname(__filename);
  12. const VERSION = process.env.VERSION || 'snapshot'; // default snapshot
  13. const FILE = process.env.FILE;
  14. const SOURCEMAPS = process.env.SOURCEMAPS === 'true'; // default false
  15. const BABEL = process.env.BABEL !== 'false'; // default true
  16. const NODE_ENV = process.env.NODE_ENV === 'development' ? 'development' : 'production'; // default prod
  17. const input = './src/index.mjs';
  18. const name = 'cytoscape';
  19. const envVariables = {
  20. 'process.env.VERSION': JSON.stringify(VERSION),
  21. 'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
  22. };
  23. const replaceOptions = {
  24. values: envVariables,
  25. preventAssignment: true
  26. };
  27. const getBabelOptions = () => ({
  28. exclude: '**/node_modules/**',
  29. babelHelpers: 'bundled'
  30. });
  31. // Ignore all node_modules dependencies
  32. const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
  33. const licenseHeaderOptions = {
  34. sourcemap: true,
  35. banner: {
  36. content: {
  37. file: path.join(__dirname, 'LICENSE')
  38. }
  39. }
  40. };
  41. const configs = [
  42. {
  43. input,
  44. output: {
  45. file: 'build/cytoscape.umd.js',
  46. format: 'umd',
  47. name,
  48. sourcemap: SOURCEMAPS ? 'inline' : false
  49. },
  50. plugins: [
  51. nodeResolve(),
  52. commonjs({ include: '**/node_modules/**' }),
  53. BABEL ? babel(getBabelOptions()) : {},
  54. replace(replaceOptions),
  55. license(licenseHeaderOptions)
  56. ]
  57. },
  58. {
  59. input,
  60. output: {
  61. file: 'build/cytoscape.min.js',
  62. format: 'umd',
  63. name
  64. },
  65. plugins: [
  66. nodeResolve(),
  67. commonjs({ include: '**/node_modules/**' }),
  68. BABEL ? babel(getBabelOptions()) : {},
  69. replace(replaceOptions),
  70. terser(),
  71. license(licenseHeaderOptions)
  72. ]
  73. },
  74. {
  75. input,
  76. output: {
  77. file: 'build/cytoscape.esm.min.mjs',
  78. format: 'es'
  79. },
  80. plugins: [
  81. nodeResolve(),
  82. commonjs({ include: '**/node_modules/**' }),
  83. BABEL ? babel(getBabelOptions()) : {},
  84. replace(replaceOptions),
  85. license(licenseHeaderOptions),
  86. terser()
  87. ]
  88. },
  89. {
  90. input,
  91. output: { file: 'build/cytoscape.cjs.js', format: 'cjs' },
  92. plugins: [
  93. nodeResolve(),
  94. commonjs({ include: '**/node_modules/**' }),
  95. BABEL ? babel(getBabelOptions()) : {},
  96. replace(replaceOptions),
  97. license(licenseHeaderOptions)
  98. ]
  99. },
  100. {
  101. input,
  102. output: { file: 'build/cytoscape.esm.mjs', format: 'es' },
  103. plugins: [
  104. nodeResolve(),
  105. commonjs({ include: '**/node_modules/**' }),
  106. BABEL ? babel(getBabelOptions()) : {},
  107. replace(replaceOptions),
  108. license(licenseHeaderOptions)
  109. ]
  110. }
  111. ];
  112. export default FILE
  113. ? configs.filter(config => config.output.file.endsWith(FILE + '.js') || config.output.file.endsWith(FILE + '.mjs'))
  114. : configs;