chore(distro): rename dist files and omit .map
This renames distribution files to: {variant}.development.js {variant}.production.min.js Additional changes: * drops .map file; users should use .development bundle for easier debugging Related to #725 BREAKING CHANGE: * distribution files have been renamed; users must update their apps accordingly if they'd like to use newer bpmn-js dists
This commit is contained in:
parent
d9d0d9dcdb
commit
ea17632311
|
@ -3,7 +3,6 @@
|
|||
var browserify = require('browserify'),
|
||||
derequire = require('browserify-derequire'),
|
||||
collapse = require('bundle-collapser/plugin'),
|
||||
concat = require('source-map-concat'),
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
flattenBundle = require('browser-pack-flat/plugin'),
|
||||
|
@ -18,10 +17,8 @@ var asyncSeries = require('./helpers').asyncSeries;
|
|||
var BANNER = fs.readFileSync(__dirname + '/../resources/banner.txt', 'utf8'),
|
||||
BANNER_MIN = fs.readFileSync(__dirname + '/../resources/banner-min.txt', 'utf8');
|
||||
|
||||
var SOURCE_MAP_HEADER = '//# sourceMappingURL=data:application/json;charset=utf-8;base64,';
|
||||
|
||||
|
||||
module.exports = function bundleAll(targets, done) {
|
||||
module.exports = function bundleAll(dest, targets, done) {
|
||||
|
||||
var fns = Object.keys(targets).map(function(k) {
|
||||
|
||||
|
@ -31,7 +28,7 @@ module.exports = function bundleAll(targets, done) {
|
|||
return function(done) {
|
||||
console.log('\nbundle ' + variant);
|
||||
|
||||
bundle(variant, entry, done);
|
||||
bundle(dest, variant, entry, done);
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -39,36 +36,6 @@ module.exports = function bundleAll(targets, done) {
|
|||
};
|
||||
|
||||
|
||||
function extractSourceMap(content) {
|
||||
|
||||
var idx = content.indexOf(SOURCE_MAP_HEADER),
|
||||
map, code;
|
||||
|
||||
if (idx !== -1) {
|
||||
code = content.substring(0, idx);
|
||||
map = content.substring(idx + SOURCE_MAP_HEADER.length);
|
||||
|
||||
map = new Buffer(map, 'base64').toString();
|
||||
|
||||
map = map.replace(/\\\\/g, '/'); // convert \\ -> /
|
||||
|
||||
var dir = __dirname;
|
||||
|
||||
var dirPattern = dir.replace(/\\/g, '/').replace(/\./g, '\\.') + '/';
|
||||
|
||||
var pattern = new RegExp(dirPattern, 'g');
|
||||
|
||||
map = map.replace(pattern, '');
|
||||
|
||||
return {
|
||||
code: code,
|
||||
map: JSON.parse(map)
|
||||
};
|
||||
} else {
|
||||
throw new Error('no attached source map');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function Timer() {
|
||||
this.reset();
|
||||
|
@ -122,10 +89,9 @@ function today() {
|
|||
].join('-');
|
||||
}
|
||||
|
||||
function bundle(variant, entry, done) {
|
||||
function bundle(dest, variant, entry, done) {
|
||||
|
||||
var src = path.resolve(entry);
|
||||
var dest = 'dist';
|
||||
|
||||
var config = {
|
||||
variant: variant,
|
||||
|
@ -187,9 +153,9 @@ function bundle(variant, entry, done) {
|
|||
|
||||
timer.done('minified');
|
||||
|
||||
fs.writeFileSync(targetFileBase + '.min.js', minified.code, 'utf8');
|
||||
fs.writeFileSync(targetFileBase + '.production.min.js', minified.code, 'utf8');
|
||||
|
||||
timer.done('saved');
|
||||
timer.done('wrote ' + targetFileBase + '.production.min.js');
|
||||
|
||||
done();
|
||||
});
|
||||
|
@ -199,7 +165,7 @@ function bundle(variant, entry, done) {
|
|||
function(done) {
|
||||
timer.start('build dev');
|
||||
|
||||
browserify(Object.assign({ debug: true }, browserifyOptions))
|
||||
browserify(browserifyOptions)
|
||||
.plugin(collapse)
|
||||
.plugin(derequire)
|
||||
.add(src)
|
||||
|
@ -211,26 +177,11 @@ function bundle(variant, entry, done) {
|
|||
return done(err);
|
||||
}
|
||||
|
||||
try {
|
||||
var bundled = extractSourceMap(result.toString('utf8'));
|
||||
var code = banner + result.toString('utf-8');
|
||||
|
||||
timer.done('extracted source map');
|
||||
fs.writeFileSync(targetFileBase + '.development.js', code, 'utf8');
|
||||
|
||||
var bannerBundled =
|
||||
concat([ bundled ])
|
||||
.prepend(banner + '\n')
|
||||
.add('//# sourceMappingURL=./' + variant + '.js.map')
|
||||
.toStringWithSourceMap();
|
||||
|
||||
timer.done('added banner');
|
||||
|
||||
fs.writeFileSync(targetFileBase + '.js', bannerBundled.code, 'utf8');
|
||||
fs.writeFileSync(targetFileBase + '.js.map', bannerBundled.map, 'utf8');
|
||||
|
||||
timer.done('all saved');
|
||||
} catch (e) {
|
||||
return done(e);
|
||||
}
|
||||
timer.done('wrote ' + targetFileBase + '.development.js');
|
||||
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue