提交 51aab9e7 编写于 作者: S susiwen8

chore: use banner and footer to wrap code

上级 2801c17e
......@@ -20,7 +20,6 @@
const path = require('path');
const {build} = require('esbuild');
const fs = require('fs');
const outFilePath = path.resolve(__dirname, '../dist/echarts.js');
......@@ -28,6 +27,7 @@ const umdMark = '// ------------- WRAPPED UMD --------------- //';
const umdWrapperHead = `
${umdMark}
(function (root, factory) {
window.__DEV__ = true;
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], factory);
......@@ -44,46 +44,23 @@ ${umdMark}
const umdWrapperTail = `
}));`;
async function wrapUMDCode() {
const code = fs.readFileSync(outFilePath, 'utf-8');
if (code.indexOf(umdMark) >= 0) {
return;
}
fs.writeFileSync(
outFilePath,
// Replaced __DEV__ with a same length string to avoid breaking source map
umdWrapperHead + code.replace(/__DEV__/g, "\'_DEV_\'") + umdWrapperTail,
'utf-8'
);
const sourceMap = JSON.parse(fs.readFileSync(outFilePath + '.map', 'utf-8'));
// Fast trick for fixing source map
sourceMap.mappings = umdWrapperHead.split('\n').map(() => '').join(';') + sourceMap.mappings;
fs.writeFileSync(outFilePath + '.map', JSON.stringify(sourceMap), 'utf-8');
}
build({
// stdio: 'inherit',
entryPoints: [path.resolve(__dirname, '../src/echarts.all.ts')],
outfile: outFilePath,
format: 'cjs',
sourcemap: true,
bundle: true,
banner: umdWrapperHead,
footer: umdWrapperTail,
watch: {
async onRebuild(error, result) {
async onRebuild(error) {
if (error) {
console.error('watch build failed:', error)
} else {
console.time('Wrap UMD');
await wrapUMDCode();
console.timeEnd('Wrap UMD');
console.log('build done')
}
},
},
}).then(async (result) => {
console.time('Wrap UMD');
await wrapUMDCode();
console.timeEnd('Wrap UMD');
}).then(async () => {
console.log('build done')
}).catch(e => console.error(e.toString()))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册