config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const nodeResolvePlugin = require('rollup-plugin-node-resolve');
  2. const uglifyPlugin = require('rollup-plugin-uglify');
  3. const ecRemoveDevPlugin = require('./rollup-plugin-ec-remove-dev');
  4. const ecLangPlugin = require('./rollup-plugin-ec-lang');
  5. const {resolve} = require('path');
  6. function getPathBasedOnECharts(path) {
  7. return resolve(__dirname, '../', path);
  8. }
  9. function getPlugins({min, lang, sourcemap, removeDev, addBundleVersion}) {
  10. let plugins = [];
  11. removeDev && plugins.push(
  12. ecRemoveDevPlugin({sourcemap})
  13. );
  14. lang && plugins.push(
  15. ecLangPlugin({lang})
  16. );
  17. plugins.push(
  18. nodeResolvePlugin()
  19. );
  20. addBundleVersion && plugins.push({
  21. outro: function () {
  22. return 'exports.bundleVersion = \'' + (+new Date()) + '\';';
  23. }
  24. });
  25. min && plugins.push(uglifyPlugin({
  26. compress: {
  27. // Eliminate __DEV__ code.
  28. // Currently, in uglify:
  29. // `var vx; if(vx) {...}` can not be removed.
  30. // `if (__DEV__) {...}` can be removed if `__DEV__` is defined as `false` in `global_defs`.
  31. // 'global_defs': {
  32. // __DEV__: false
  33. // },
  34. 'dead_code': true
  35. }
  36. }));
  37. return plugins;
  38. }
  39. /**
  40. * @param {Object} [opt]
  41. * @param {string} [opt.type=''] '' or 'simple' or 'common'
  42. * @param {boolean} [opt.min=false]
  43. * @param {string} [opt.lang=undefined] null/undefined/'' or 'en' or 'fi' or a file path.
  44. * @param {string} [opt.input=undefined] If set, `opt.output` is required too, and `opt.type` is ignored.
  45. * @param {string} [opt.output=undefined] If set, `opt.input` is required too, and `opt.type` is ignored.
  46. * @param {boolean} [opt.sourcemap] If set, `opt.input` is required too, and `opt.type` is ignored.
  47. * @param {boolean} [opt.removeDev]
  48. * @param {string} [opt.format='umd'] If set, `opt.input` is required too, and `opt.type` is ignored.
  49. * @param {boolean} [opt.addBundleVersion=false] Only for debug in watch, prompt that the two build is different.
  50. */
  51. exports.createECharts = function (opt = {}) {
  52. let srcType = opt.type ? '.' + opt.type : '.all';
  53. let postfixType = opt.type ? '.' + opt.type : '';
  54. let postfixMin = opt.min ? '.min' : '';
  55. let postfixLang = opt.lang ? '-' + opt.lang.toLowerCase() : '';
  56. let input = opt.input;
  57. let output = opt.output;
  58. let sourcemap = opt.sourcemap;
  59. let format = opt.format || 'umd';
  60. if (input != null || output != null) {
  61. // Based on process.cwd();
  62. input = resolve(input);
  63. output = resolve(output);
  64. }
  65. else {
  66. input = getPathBasedOnECharts(`./echarts${srcType}.js`);
  67. output = getPathBasedOnECharts(`dist/echarts${postfixLang}${postfixType}${postfixMin}.js`);
  68. }
  69. return {
  70. plugins: getPlugins(opt),
  71. input: input,
  72. legacy: true, // Support IE8-
  73. output: {
  74. name: 'echarts',
  75. format: format,
  76. sourcemap: sourcemap,
  77. legacy: true, // Must be declared both in inputOptions and outputOptions.
  78. file: output
  79. },
  80. watch: {
  81. include: [
  82. getPathBasedOnECharts('./src/**'),
  83. getPathBasedOnECharts('./echarts*.js'),
  84. getPathBasedOnECharts('../zrender/src/**')
  85. ]
  86. }
  87. };
  88. };
  89. /**
  90. * @param {boolean} [min=false]
  91. */
  92. exports.createBMap = function (min) {
  93. let postfix = min ? '.min' : '';
  94. return {
  95. plugins: getPlugins({min}),
  96. input: getPathBasedOnECharts(`./extension-src/bmap/bmap.js`),
  97. legacy: true, // Support IE8-
  98. external: ['echarts'],
  99. output: {
  100. name: 'bmap',
  101. format: 'umd',
  102. sourcemap: !min,
  103. legacy: true, // Must be declared both in inputOptions and outputOptions.
  104. globals: {
  105. // For UMD `global.echarts`
  106. echarts: 'echarts'
  107. },
  108. file: getPathBasedOnECharts(`dist/extension/bmap${postfix}.js`)
  109. },
  110. watch: {
  111. include: [getPathBasedOnECharts('./extension-src/bmap/**')]
  112. }
  113. };
  114. };
  115. /**
  116. * @param {boolean} [min=false]
  117. */
  118. exports.createDataTool = function (min) {
  119. let postfix = min ? '.min' : '';
  120. return {
  121. plugins: getPlugins({min}),
  122. input: getPathBasedOnECharts(`./extension-src/dataTool/index.js`),
  123. legacy: true, // Support IE8-
  124. external: ['echarts'],
  125. output: {
  126. name: 'dataTool',
  127. format: 'umd',
  128. sourcemap: !min,
  129. legacy: true, // Must be declared both in inputOptions and outputOptions.
  130. globals: {
  131. // For UMD `global.echarts`
  132. echarts: 'echarts'
  133. },
  134. file: getPathBasedOnECharts(`dist/extension/dataTool${postfix}.js`)
  135. },
  136. watch: {
  137. include: [getPathBasedOnECharts('./extension-src/dataTool/**')]
  138. }
  139. };
  140. };