dev-fast.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 path = require('path');
  20. const {build} = require('esbuild');
  21. const outFilePath = path.resolve(__dirname, '../dist/echarts.js');
  22. const umdMark = '// ------------- WRAPPED UMD --------------- //';
  23. const umdWrapperHead = `
  24. ${umdMark}
  25. (function (root, factory) {
  26. window.__DEV__ = true;
  27. if (typeof define === 'function' && define.amd) {
  28. // AMD. Register as an anonymous module.
  29. define(['exports'], factory);
  30. } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
  31. // CommonJS
  32. factory(exports);
  33. } else {
  34. // Browser globals
  35. factory((root.echarts = {}));
  36. }
  37. }(typeof self !== 'undefined' ? self : this, function (exports, b) {
  38. `;
  39. const umdWrapperTail = `
  40. }));`;
  41. build({
  42. entryPoints: [path.resolve(__dirname, '../src/echarts.all.ts')],
  43. outfile: outFilePath,
  44. format: 'cjs',
  45. sourcemap: true,
  46. bundle: true,
  47. banner: umdWrapperHead,
  48. footer: umdWrapperTail,
  49. watch: {
  50. async onRebuild(error) {
  51. if (error) {
  52. console.error('watch build failed:', error)
  53. } else {
  54. console.log('build done')
  55. }
  56. },
  57. },
  58. }).then(async () => {
  59. console.log('build done')
  60. }).catch(e => console.error(e.toString()))