Açıklama Yok

rollup.config.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 componentsFold = 'src/components';
  37. const cModuleNames = fs.readdirSync(path.resolve(componentsFold));
  38. const cModuleMap = cModuleNames.reduce((prev, name) => {
  39. const modulePath = `${componentsFold}/${name}`;
  40. prev[name] = `${modulePath}/index.ts`;
  41. const child = fs.readdirSync(path.resolve(modulePath));
  42. child.forEach(c => {
  43. const childFoldPath = `${modulePath}/${c}`;
  44. const isDir = fs.statSync(childFoldPath).isDirectory();
  45. if (isDir) {
  46. if (fs.existsSync(`${childFoldPath}/index.tsx`)) {
  47. prev[c] = `${childFoldPath}/index.tsx`;
  48. }
  49. if (c === 'Common' && fs.existsSync(childFoldPath) && fs.statSync(childFoldPath).isDirectory()) {
  50. const commonComponentsArr = fs.readdirSync(childFoldPath);
  51. commonComponentsArr.forEach(commonComponentFold => {
  52. const commonComponentFoldPath = `${childFoldPath}/${commonComponentFold}`;
  53. const isCommonComponentDir = fs.statSync(commonComponentFoldPath).isDirectory();
  54. if (isCommonComponentDir && fs.existsSync(`${commonComponentFoldPath}/index.tsx`)) {
  55. prev[`${commonComponentFold}`] = `${commonComponentFoldPath}/index.tsx`;
  56. }
  57. });
  58. }
  59. }
  60. });
  61. return prev;
  62. }, {});
  63. const extensions = ['.js', '.jsx', '.ts', '.tsx'];
  64. export default {
  65. input: {
  66. '.': "src/lib-build.js",
  67. ...cModuleMap
  68. },
  69. output: [
  70. {
  71. dir: "lib",
  72. sourcemap: true,
  73. entryFileNames: '[name]/index.js',
  74. exports: 'named',
  75. // file: "lib/bundle.js",
  76. format: "cjs"
  77. },
  78. {
  79. dir: "eslib",
  80. sourcemap: true,
  81. entryFileNames: '[name]/index.js',
  82. exports: 'named',
  83. // file: "lib/bundle.js",
  84. format: "es"
  85. }
  86. ],
  87. plugins: [
  88. peerDepsExternal(),
  89. resolve({
  90. mainFields: ['jsnext'],
  91. preferBuiltins: true,
  92. browser: true,
  93. extensions,
  94. }),
  95. commonjs({
  96. include: 'node_modules/**',
  97. browser: true,
  98. namedExports: {
  99. ...getNamedExports([
  100. 'prop-types',
  101. 'draft-js',
  102. ]),
  103. 'braft-extensions/dist/emoticon': ['defaultEmoticons']
  104. },
  105. }),
  106. babel({
  107. exclude: "node_modules/**",
  108. runtimeHelpers: true,
  109. extensions,
  110. }),
  111. image(),
  112. json(),
  113. // url(),
  114. // less(),
  115. postcss({
  116. extensions: ['.css', '.less'],
  117. plugins: [
  118. autoprefixer(),
  119. postcssUrl({
  120. url: 'inline'
  121. }),
  122. ],
  123. modules: true,
  124. }),
  125. alias({
  126. entries: [
  127. { find: '@', replacement: 'src' },
  128. { find: '@components', replacement: 'src/components' },
  129. ]
  130. }),
  131. visualizer({
  132. sourcemap: true,
  133. open: true,
  134. }),
  135. analyze(),
  136. ],
  137. onwarn: function(warning) {
  138. // Skip certain warnings
  139. // should intercept ... but doesn't in some rollup versions
  140. if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
  141. // console.warn everything else
  142. console.warn( warning.message );
  143. }
  144. };