提交 a921ad03 编写于 作者: S sushuang

print bundle version to aid debug.

上级 1f1e6895
...@@ -95,7 +95,8 @@ function run() { ...@@ -95,7 +95,8 @@ function run() {
input: commander.input, input: commander.input,
output: commander.output, output: commander.output,
sourcemap: commander.sourcemap, sourcemap: commander.sourcemap,
format: commander.format || 'umd' format: commander.format || 'umd',
addBundleVersion: isWatch
}; };
validateIO(opt.input, opt.output); validateIO(opt.input, opt.output);
......
...@@ -12,8 +12,9 @@ function getPathBasedOnECharts(path) { ...@@ -12,8 +12,9 @@ function getPathBasedOnECharts(path) {
/** /**
* @param {boolean} [min=false] * @param {boolean} [min=false]
* @param {string} [lang=null] null/undefined/'' or 'en' or 'fi' or a file path * @param {string} [lang=null] null/undefined/'' or 'en' or 'fi' or a file path
* @param {boolean} [addBundleVersion=false]
*/ */
function getPlugins(min, lang) { function getPlugins(min, lang, addBundleVersion) {
let plugins = [ let plugins = [
ecDevPlugin() ecDevPlugin()
]; ];
...@@ -26,6 +27,12 @@ function getPlugins(min, lang) { ...@@ -26,6 +27,12 @@ function getPlugins(min, lang) {
nodeResolvePlugin() nodeResolvePlugin()
); );
addBundleVersion && plugins.push({
outro: function () {
return 'exports.bundleVersion = "' + (+new Date()) + '";';
}
});
min && plugins.push(uglifyPlugin({ min && plugins.push(uglifyPlugin({
compress: { compress: {
// Eliminate __DEV__ code. // Eliminate __DEV__ code.
...@@ -51,6 +58,7 @@ function getPlugins(min, lang) { ...@@ -51,6 +58,7 @@ function getPlugins(min, lang) {
* @param {string} [opt.output=undefined] If set, `opt.input` is required too, and `opt.type` is ignored. * @param {string} [opt.output=undefined] If set, `opt.input` is required too, and `opt.type` is ignored.
* @param {boolean} [opt.sourcemap] If set, `opt.input` is required too, and `opt.type` is ignored. * @param {boolean} [opt.sourcemap] If set, `opt.input` is required too, and `opt.type` is ignored.
* @param {string} [opt.format='umd'] If set, `opt.input` is required too, and `opt.type` is ignored. * @param {string} [opt.format='umd'] If set, `opt.input` is required too, and `opt.type` is ignored.
* @param {boolean} [opt.addBundleVersion=false] Only for debug in watch, prompt that the two build is different.
*/ */
exports.createECharts = function (opt) { exports.createECharts = function (opt) {
opt = opt || {}; opt = opt || {};
...@@ -78,7 +86,7 @@ exports.createECharts = function (opt) { ...@@ -78,7 +86,7 @@ exports.createECharts = function (opt) {
} }
return { return {
plugins: getPlugins(opt.min, opt.lang), plugins: getPlugins(opt.min, opt.lang, opt.addBundleVersion),
input: input, input: input,
legacy: true, // Support IE8- legacy: true, // Support IE8-
output: { output: {
......
...@@ -45,4 +45,68 @@ ...@@ -45,4 +45,68 @@
window.__ECHARTS__DEFAULT__RENDERER__ = matchResult[1]; window.__ECHARTS__DEFAULT__RENDERER__ = matchResult[1];
} }
// Mount bundle version print.
if (typeof require !== 'undefined') {
var originalRequire = require;
window.require = function (deps, cb) {
var newCb = function () {
if (deps && deps instanceof Array) {
printBundleVersion(deps, [].slice.call(arguments));
}
cb && cb.apply(this, arguments);
};
return originalRequire.call(this, deps, newCb);
};
}
function printBundleVersion(bundleIds, bundles) {
var content = [];
for (var i = 0; i < bundleIds.length; i++) {
var bundle = bundles[i];
var bundleVersion = bundle && bundle.bundleVersion;
if (bundleVersion) {
var date = new Date(+bundleVersion);
// Check whether timestamp.
if (!isNaN(+date)) {
bundleVersion = date.getHours() + ':' + date.getMinutes() + ': '
+ '<span style="color:yellow">'
+ date.getSeconds() + '.' + date.getMilliseconds()
+ '</span>';
}
else {
bundleVersion = encodeHTML(bundleVersion);
}
content.push(encodeHTML(bundleIds[i]) + '.js: ' + bundleVersion);
}
}
var domId = 'ec-test-bundle-version';
var dom = document.getElementById(domId);
if (!dom) {
dom = document.createElement('div');
dom.setAttribute('id', domId);
dom.style.cssText = [
'background: rgb(52,56,64)',
'color: rgb(215,215,215)',
'position: fixed',
'right: 0',
'top: 0',
'font-size: 10px',
'padding: 1px 2px 1px 2px',
'border-bottom-left-radius: 3px'
].join(';');
document.body.appendChild(dom);
}
dom.innerHTML = content.join('');
}
function encodeHTML(source) {
return String(source)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}
})(); })();
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册