rollup-plugin-ec-dev.js 1006 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Define variable `__DEV__`.
  3. *
  4. * Usage:
  5. *
  6. * import ecDevPlugin from 'echats/build/rollup-plugin-ec-dev';
  7. * let rollupConfig = {
  8. * plugins: [
  9. * ecDevPlugin(),
  10. * ...
  11. * ]
  12. * };
  13. *
  14. * We use global variable `__DEV__` for convenience, but it bring trouble
  15. * while building: it is not able to make sure the decaration of `__DEV__`
  16. * occures in front of the whole code if we use ES module import. So we
  17. * use the plugin to handle that.
  18. *
  19. * See `echarts/src/config.js`.
  20. */
  21. module.exports = function (opt) {
  22. return {
  23. intro: function () {
  24. return [
  25. 'if (typeof __DEV__ === "undefined") {',
  26. ' if (typeof window !== "undefined") {',
  27. ' window.__DEV__ = true;',
  28. ' }',
  29. ' else if (typeof global !== "undefined") {',
  30. ' global.__DEV__ = true;',
  31. ' }',
  32. '}'
  33. ].join('\n');
  34. }
  35. };
  36. };