Skip to content

Commit

Permalink
make only minified with sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Mar 1, 2021
1 parent 0869970 commit 7d0145a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
3 changes: 1 addition & 2 deletions tasks/partial_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ if(process.argv.length > 2) {

name: out,
index: path.join(constants.pathToLib, 'index-' + out + '.js'),
sourceMap: path.join(constants.pathToDist, 'plotly-' + out + '.js.map'),
dist: path.join(constants.pathToDist, 'plotly-' + out + '.js'),
sourceMap: path.join(constants.pathToDist, 'plotly-' + out + '.min.js.map'),
distMin: path.join(constants.pathToDist, 'plotly-' + out + '.min.js')
};

Expand Down
51 changes: 33 additions & 18 deletions tasks/util/browserify_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var strictD3 = require('./strict_d3');
* - standalone {string}
* - debug {boolean} [optional]
* Additional option:
* - pathToSourceMap {string} path to destination source map
* - pathToMinBundle {string} path to destination minified bundle
* - noCompress {boolean} skip attribute meta compression?
* @param {function} cb callback
Expand Down Expand Up @@ -62,26 +63,40 @@ module.exports = function _bundle(pathToIndex, pathToBundle, opts, cb) {
});

if(pathToMinBundle) {
bundleStream
.pipe(applyDerequire())
.pipe(minify(constants.uglifyOptions))
.pipe(fs.createWriteStream(pathToMinBundle))
.on('finish', function() {
logger(pathToMinBundle);
done();
});
var minifyOpts = {
ecma: 5,
mangle: true,
output: {
beautify: false,
ascii_only: true
},

sourceMap: !!sourceMap
};

if(sourceMap) {
bundleStream
.pipe(applyDerequire())
.pipe(minify(minifyOpts))
.pipe(exorcist(sourceMap))
.pipe(fs.createWriteStream(pathToMinBundle))
.on('finish', function() {
logger(pathToMinBundle);
done();
});
} else {
bundleStream
.pipe(applyDerequire())
.pipe(minify(minifyOpts))
.pipe(fs.createWriteStream(pathToMinBundle))
.on('finish', function() {
logger(pathToMinBundle);
done();
});
}
}

if(sourceMap) {
bundleStream
.pipe(applyDerequire())
.pipe(exorcist(sourceMap))
.pipe(fs.createWriteStream(pathToBundle))
.on('finish', function() {
logger(pathToBundle);
done();
});
} else {
if(pathToBundle) {
bundleStream
.pipe(applyDerequire())
.pipe(fs.createWriteStream(pathToBundle))
Expand Down
11 changes: 0 additions & 11 deletions tasks/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,6 @@ module.exports = {
testContainerUrl: 'http://localhost:9010/',
testContainerHome: '/var/www/streambed/image_server/plotly.js',

uglifyOptions: {
ecma: 5,
mangle: true,
output: {
beautify: false,
ascii_only: true
},

sourceMap: false
},

licenseDist: [
'/**',
'* plotly.js v' + pkg.version,
Expand Down
13 changes: 10 additions & 3 deletions tasks/util/wrap_locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var path = require('path');
var minify = require('minify-stream');
var intoStream = require('into-stream');

var constants = require('./constants');

var prefix = 'var locale=';
var suffix = ';if(typeof Plotly === \'undefined\') {window.PlotlyLocales = window.PlotlyLocales || []; window.PlotlyLocales.push(locale);} else {Plotly.register(locale);}';

Expand All @@ -26,7 +24,16 @@ module.exports = function wrapLocale(pathToInput, pathToOutput) {
var rawOut = prefix + data.substr(moduleStart, moduleEnd - moduleStart) + suffix;

intoStream(rawOut)
.pipe(minify(constants.uglifyOptions))
.pipe(minify({
ecma: 5,
mangle: true,
output: {
beautify: false,
ascii_only: true
},

sourceMap: false
}))
.pipe(fs.createWriteStream(pathToOutput))
.on('finish', function() {
logger(pathToOutput);
Expand Down

0 comments on commit 7d0145a

Please sign in to comment.