config.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. const nodeResolvePlugin = require('rollup-plugin-node-resolve');
  20. const uglifyPlugin = require('rollup-plugin-uglify');
  21. const ecRemoveDevPlugin = require('./rollup-plugin-ec-remove-dev');
  22. const ecLangPlugin = require('./rollup-plugin-ec-lang');
  23. const {resolve} = require('path');
  24. const preamble = require('./preamble');
  25. function getPathBasedOnECharts(path) {
  26. return resolve(__dirname, '../', path);
  27. }
  28. function getPlugins({min, lang, sourcemap, removeDev, addBundleVersion}) {
  29. let plugins = [];
  30. removeDev && plugins.push(
  31. ecRemoveDevPlugin({sourcemap})
  32. );
  33. lang && plugins.push(
  34. ecLangPlugin({lang})
  35. );
  36. plugins.push(
  37. nodeResolvePlugin()
  38. );
  39. addBundleVersion && plugins.push({
  40. outro: function () {
  41. return 'exports.bundleVersion = \'' + (+new Date()) + '\';';
  42. }
  43. });
  44. min && plugins.push(uglifyPlugin({
  45. compress: {
  46. // Eliminate __DEV__ code.
  47. // Currently, in uglify:
  48. // `var vx; if(vx) {...}` can not be removed.
  49. // `if (__DEV__) {...}` can be removed if `__DEV__` is defined as `false` in `global_defs`.
  50. // 'global_defs': {
  51. // __DEV__: false
  52. // },
  53. 'dead_code': true
  54. },
  55. output: {
  56. preamble: preamble.js
  57. }
  58. }));
  59. return plugins;
  60. }
  61. /**
  62. * @param {Object} [opt]
  63. * @param {string} [opt.type=''] '' or 'simple' or 'common'
  64. * @param {boolean} [opt.min=false]
  65. * @param {string} [opt.lang=undefined] null/undefined/'' or 'en' or 'fi' or a file path.
  66. * @param {string} [opt.input=undefined] If set, `opt.output` is required too, and `opt.type` is ignored.
  67. * @param {string} [opt.output=undefined] If set, `opt.input` is required too, and `opt.type` is ignored.
  68. * @param {boolean} [opt.sourcemap] If set, `opt.input` is required too, and `opt.type` is ignored.
  69. * @param {boolean} [opt.removeDev]
  70. * @param {string} [opt.format='umd'] If set, `opt.input` is required too, and `opt.type` is ignored.
  71. * @param {boolean} [opt.addBundleVersion=false] Only for debug in watch, prompt that the two build is different.
  72. */
  73. exports.createECharts = function (opt = {}) {
  74. let min = opt.min;
  75. let srcType = opt.type ? '.' + opt.type : '.all';
  76. let postfixType = opt.type ? '.' + opt.type : '';
  77. let postfixMin = min ? '.min' : '';
  78. let postfixLang = opt.lang ? '-' + opt.lang.toLowerCase() : '';
  79. let input = opt.input;
  80. let output = opt.output;
  81. let sourcemap = opt.sourcemap;
  82. let format = opt.format || 'umd';
  83. if (input != null || output != null) {
  84. // Based on process.cwd();
  85. input = resolve(input);
  86. output = resolve(output);
  87. }
  88. else {
  89. input = getPathBasedOnECharts(`./echarts${srcType}.js`);
  90. output = getPathBasedOnECharts(`dist/echarts${postfixLang}${postfixType}${postfixMin}.js`);
  91. }
  92. return {
  93. plugins: getPlugins(opt),
  94. input: input,
  95. legacy: true, // Support IE8-
  96. output: {
  97. name: 'echarts',
  98. format: format,
  99. sourcemap: sourcemap,
  100. legacy: true, // Must be declared both in inputOptions and outputOptions.
  101. file: output
  102. },
  103. watch: {
  104. include: [
  105. getPathBasedOnECharts('./src/**'),
  106. getPathBasedOnECharts('./echarts*.js'),
  107. getPathBasedOnECharts('../zrender/src/**')
  108. ]
  109. }
  110. };
  111. };
  112. /**
  113. * @param {boolean} [min=false]
  114. */
  115. exports.createBMap = function (min) {
  116. let postfix = min ? '.min' : '';
  117. return {
  118. plugins: getPlugins({min}),
  119. input: getPathBasedOnECharts(`./extension-src/bmap/bmap.js`),
  120. legacy: true, // Support IE8-
  121. external: ['echarts'],
  122. output: {
  123. name: 'bmap',
  124. format: 'umd',
  125. sourcemap: !min,
  126. legacy: true, // Must be declared both in inputOptions and outputOptions.
  127. globals: {
  128. // For UMD `global.echarts`
  129. echarts: 'echarts'
  130. },
  131. file: getPathBasedOnECharts(`dist/extension/bmap${postfix}.js`)
  132. },
  133. watch: {
  134. include: [getPathBasedOnECharts('./extension-src/bmap/**')]
  135. }
  136. };
  137. };
  138. /**
  139. * @param {boolean} [min=false]
  140. */
  141. exports.createDataTool = function (min) {
  142. let postfix = min ? '.min' : '';
  143. return {
  144. plugins: getPlugins({min}),
  145. input: getPathBasedOnECharts(`./extension-src/dataTool/index.js`),
  146. legacy: true, // Support IE8-
  147. external: ['echarts'],
  148. output: {
  149. name: 'dataTool',
  150. format: 'umd',
  151. sourcemap: !min,
  152. legacy: true, // Must be declared both in inputOptions and outputOptions.
  153. globals: {
  154. // For UMD `global.echarts`
  155. echarts: 'echarts'
  156. },
  157. file: getPathBasedOnECharts(`dist/extension/dataTool${postfix}.js`)
  158. },
  159. watch: {
  160. include: [getPathBasedOnECharts('./extension-src/dataTool/**')]
  161. }
  162. };
  163. };