Build sourcemaps via magic-string
This commit is contained in:
parent
d17e53bbf6
commit
62f1cd2f58
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@ tmp/**/*
|
||||
*.sublime-*
|
||||
_site
|
||||
dist/*.js
|
||||
dist/*.map
|
||||
coverage/
|
||||
*.js.html
|
||||
index.html
|
||||
|
@ -1,6 +1,7 @@
|
||||
var fs = require('fs'),
|
||||
UglifyJS = require('uglify-js'),
|
||||
zlib = require('zlib'),
|
||||
MagicString = require('magic-string'),
|
||||
|
||||
deps = require('./deps.js').deps;
|
||||
|
||||
@ -69,12 +70,21 @@ function loadSilently(path) {
|
||||
}
|
||||
}
|
||||
|
||||
function combineFiles(files) {
|
||||
var content = '';
|
||||
function bundleFiles(files, copy) {
|
||||
var bundle = new MagicString.Bundle();
|
||||
|
||||
for (var i = 0, len = files.length; i < len; i++) {
|
||||
content += fs.readFileSync(files[i], 'utf8') + '\n\n';
|
||||
bundle.addSource({
|
||||
filename: files[i],
|
||||
content: new MagicString( fs.readFileSync(files[i], 'utf8') + '\n\n' )
|
||||
});
|
||||
}
|
||||
return content;
|
||||
|
||||
bundle.prepend(
|
||||
copy + '(function (window, document, undefined) {'
|
||||
).append('}(window, document));');
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
function bytesToKB(bytes) {
|
||||
@ -85,15 +95,19 @@ exports.build = function (callback, version, compsBase32, buildName) {
|
||||
|
||||
var files = getFiles(compsBase32);
|
||||
|
||||
console.log('Concatenating and compressing ' + files.length + ' files...');
|
||||
console.log('Bundling and compressing ' + files.length + ' files...');
|
||||
|
||||
var copy = fs.readFileSync('src/copyright.js', 'utf8').replace('{VERSION}', version),
|
||||
intro = '(function (window, document, undefined) {',
|
||||
outro = '}(window, document));',
|
||||
newSrc = copy + intro + combineFiles(files) + outro,
|
||||
|
||||
pathPart = 'dist/leaflet' + (buildName ? '-' + buildName : ''),
|
||||
filenamePart = 'leaflet' + (buildName ? '-' + buildName : ''),
|
||||
pathPart = 'dist/' + filenamePart,
|
||||
srcPath = pathPart + '-src.js',
|
||||
mapPath = pathPart + '-src.map',
|
||||
srcFilename = filenamePart + '-src.js',
|
||||
mapFilename = filenamePart + '-src.map',
|
||||
|
||||
bundle = bundleFiles(files, copy),
|
||||
newSrc = bundle.toString() + '\n//# sourceMappingURL=' + mapFilename,
|
||||
|
||||
oldSrc = loadSilently(srcPath),
|
||||
srcDelta = getSizeDelta(newSrc, oldSrc, true);
|
||||
@ -102,6 +116,11 @@ exports.build = function (callback, version, compsBase32, buildName) {
|
||||
|
||||
if (newSrc !== oldSrc) {
|
||||
fs.writeFileSync(srcPath, newSrc);
|
||||
fs.writeFileSync(mapPath, bundle.generateMap({
|
||||
file: srcFilename,
|
||||
includeContent: true,
|
||||
hires: false
|
||||
}));
|
||||
console.log('\tSaved to ' + srcPath);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
"karma-mocha": "~0.2.0",
|
||||
"karma-phantomjs-launcher": "^0.2.0",
|
||||
"karma-safari-launcher": "~0.1.1",
|
||||
"magic-string": "^0.6.4",
|
||||
"mocha": "~2.2.5",
|
||||
"tin": "^0.5.0",
|
||||
"uglify-js": "~2.4.23"
|
||||
|
Loading…
Reference in New Issue
Block a user