Bez popisu

rollup.config.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import resolve from "@rollup/plugin-node-resolve";
  2. import commonjs from "@rollup/plugin-commonjs";
  3. import image from '@rollup/plugin-image';
  4. import alias from '@rollup/plugin-alias';
  5. import postcss from 'rollup-plugin-postcss-modules'
  6. import babel from "rollup-plugin-babel";
  7. import json from "rollup-plugin-json";
  8. import autoprefixer from 'autoprefixer';
  9. import postcssUrl from 'postcss-url';
  10. import peerDepsExternal from 'rollup-plugin-peer-deps-external';
  11. import visualizer from 'rollup-plugin-visualizer';
  12. import analyze from 'rollup-plugin-analyzer';
  13. // import url from '@rollup/plugin-url';
  14. // import less from "rollup-plugin-less";
  15. import nodeEval from 'node-eval';
  16. export function getModuleExports(moduleId) {
  17. const id = require.resolve(moduleId)
  18. const moduleOut = nodeEval(fs.readFileSync(id).toString(), id)
  19. let result = []
  20. const excludeExports = /^(default|__)/
  21. if (moduleOut && typeof moduleOut === 'object') {
  22. result = Object.keys(moduleOut)
  23. .filter(name => !excludeExports.test(name))
  24. }
  25. return result
  26. }
  27. export function getNamedExports(moduleIds) {
  28. const result = {}
  29. moduleIds.forEach( id => {
  30. result[id] = getModuleExports(id)
  31. })
  32. return result
  33. }
  34. const fs = require('fs');
  35. const path = require('path');
  36. const componentFold = 'src/components';
  37. const cModuleNames = fs.readdirSync(path.resolve(componentFold));
  38. const cModuleMap = cModuleNames.reduce((prev, name) => {
  39. prev[name] = `${componentFold}/${name}/index.ts`;
  40. return prev;
  41. }, {});
  42. const extensions = ['.js', '.jsx', '.ts', '.tsx'];
  43. export default {
  44. input: {
  45. '.': "src/lib-build.js",
  46. ...cModuleMap
  47. },
  48. output: [
  49. {
  50. dir: "lib",
  51. sourcemap: true,
  52. entryFileNames: '[name]/index.js',
  53. exports: 'named',
  54. // file: "lib/bundle.js",
  55. format: "cjs"
  56. },
  57. {
  58. dir: "eslib",
  59. sourcemap: true,
  60. entryFileNames: '[name]/index.js',
  61. exports: 'named',
  62. // file: "lib/bundle.js",
  63. format: "es"
  64. }
  65. ],
  66. plugins: [
  67. peerDepsExternal(),
  68. resolve({
  69. mainFields: ['jsnext'],
  70. preferBuiltins: true,
  71. browser: true,
  72. extensions,
  73. }),
  74. commonjs({
  75. include: 'node_modules/**',
  76. browser: true,
  77. namedExports: {
  78. ...getNamedExports([
  79. 'prop-types',
  80. 'draft-js',
  81. ]),
  82. 'braft-extensions/dist/emoticon': ['defaultEmoticons']
  83. },
  84. }),
  85. babel({
  86. exclude: "node_modules/**",
  87. runtimeHelpers: true,
  88. extensions,
  89. }),
  90. image(),
  91. json(),
  92. // url(),
  93. // less(),
  94. postcss({
  95. extensions: ['.css', '.less'],
  96. plugins: [
  97. autoprefixer(),
  98. postcssUrl({
  99. url: 'inline'
  100. }),
  101. ],
  102. modules: true,
  103. }),
  104. alias({
  105. entries: [
  106. { find: '@', replacement: 'src' },
  107. { find: '@components', replacement: 'src/components' },
  108. ]
  109. }),
  110. visualizer({
  111. sourcemap: true,
  112. open: true,
  113. }),
  114. analyze(),
  115. ],
  116. onwarn: function(warning) {
  117. // Skip certain warnings
  118. // should intercept ... but doesn't in some rollup versions
  119. if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
  120. // console.warn everything else
  121. console.warn( warning.message );
  122. }
  123. };