diff --git a/build/dev-fast.js b/build/dev-fast.js index d609f16520b5d9ed437c15a0201653fa95b0984b..412eb8218c02e6d016dbc657d499a421d3c92da1 100644 --- a/build/dev-fast.js +++ b/build/dev-fast.js @@ -2,6 +2,8 @@ const chokidar = require('chokidar'); const path = require('path'); const {build} = require('esbuild'); const fs = require('fs'); +const debounce = require('lodash.debounce'); +const sourceMap = require('source-map'); const outFilePath = path.resolve(__dirname, '../dist/echarts.js'); @@ -23,9 +25,18 @@ const umdWrapperHead = ` const umdWrapperTail = ` }));`; -// attach properties to the exports object to define -// the exported module properties. -exports.action = function () {}; +async function wrapUMDCode() { + const consumer = await new sourceMap.SourceMapConsumer(fs.readFileSync(outFilePath + '.map', 'utf8')); + const node = sourceMap.SourceNode.fromStringWithSourceMap(fs.readFileSync(outFilePath, 'utf-8'), consumer); + // add six empty lines + node.prepend(umdWrapperHead); + node.add(umdWrapperTail); + const res = node.toStringWithSourceMap({ + file: outFilePath + }); + fs.writeFileSync(outFilePath, res.code, 'utf-8'); + fs.writeFileSync(outFilePath + '.map', res.map.toString(), 'utf-8'); +} function rebuild() { build({ @@ -33,20 +44,22 @@ function rebuild() { entryPoints: [path.resolve(__dirname, '../echarts.all.ts')], outfile: outFilePath, format: 'cjs', + sourcemap: true, bundle: true, }).catch(e => { console.error(e.toString()); }).then(() => { - const mainCode = fs.readFileSync(outFilePath, 'utf-8'); - fs.writeFileSync(outFilePath, umdWrapperHead + mainCode + umdWrapperTail) + console.time('Wrap UMD'); + wrapUMDCode(); + console.timeEnd('Wrap UMD'); }) } +const debouncedRebuild = debounce(rebuild, 200); + chokidar.watch([ path.resolve(__dirname, '../src/**/*.ts'), path.resolve(__dirname, '../node_modules/zrender/src/**/*.ts'), ], { persistent: true -}).on('change', rebuild).on('ready', function () { - rebuild(); -}) \ No newline at end of file +}).on('all', debouncedRebuild); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 5514063735d7036e0562cae385ed55a90fc0a81c..9fbae777924f5a94944673f67b15f28aacad410b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -70,6 +70,12 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true } } }, @@ -96,6 +102,12 @@ "lodash": "^4.17.13", "to-fast-properties": "^2.0.0" } + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true } } }, @@ -5822,6 +5834,12 @@ "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, + "lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=", + "dev": true + }, "lodash.get": { "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", @@ -7441,6 +7459,12 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true + }, + "source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "dev": true } } }, @@ -7603,9 +7627,9 @@ } }, "source-map": { - "version": "0.5.7", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", - "integrity": "sha1-igOdLRAh0i0eoUyA2OpGi6LvP8w=", + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", "dev": true }, "source-map-resolve": { diff --git a/package.json b/package.json index 113298f8254ba65e669fd8ad6006436e450a1a37..84c3d9a69b0021eb92c1232e51cb6b3ea67376c0 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "jest-canvas-mock": "^2.2.0", "jsdom": "^15.2.1", "jshint": "2.10.2", + "lodash.debounce": "^4.0.8", "open": "6.4.0", "pixelmatch": "5.0.2", "pngjs": "3.4.0", @@ -70,6 +71,7 @@ "serve-handler": "6.1.1", "slugify": "1.3.4", "socket.io": "2.2.0", + "source-map": "^0.7.3", "typescript": "^3.8.3" } }