minify.js (lodash-4.0.0) | : | minify.js (lodash-4.17.21) | ||
---|---|---|---|---|
'use strict'; | 'use strict'; | |||
var _ = require('lodash'), | const _ = require('lodash'); | |||
fs = require('fs-extra'), | const fs = require('fs-extra'); | |||
uglify = require('uglify-js'); | const uglify = require('uglify-js'); | |||
var uglifyOptions = require('./uglify.options.js'); | const uglifyOptions = require('./uglify.options'); | |||
/*----------------------------------------------------------------------------*/ | /*----------------------------------------------------------------------------*/ | |||
function minify(inpath, outpath, callback, options) { | /** | |||
if (_.isFunction(outpath)) { | * Asynchronously minifies the file at `srcPath`, writes it to `destPath`, and | |||
* invokes `callback` upon completion. The callback is invoked with one argument | ||||
: | ||||
* (error). | ||||
* | ||||
* If unspecified, `destPath` is `srcPath` with an extension of `.min.js`. | ||||
* (e.g. the `destPath` of `path/to/foo.js` would be `path/to/foo.min.js`) | ||||
* | ||||
* @param {string} srcPath The path of the file to minify. | ||||
* @param {string} [destPath] The path to write the file to. | ||||
* @param {Function} callback The function invoked upon completion. | ||||
* @param {Object} [option] The UglifyJS options object. | ||||
*/ | ||||
function minify(srcPath, destPath, callback, options) { | ||||
if (_.isFunction(destPath)) { | ||||
if (_.isObject(callback)) { | if (_.isObject(callback)) { | |||
options = callback; | options = callback; | |||
} | } | |||
callback = outpath; | callback = destPath; | |||
outpath = undefined; | destPath = undefined; | |||
} | } | |||
if (!outpath) { | if (!destPath) { | |||
outpath = inpath.replace(/(?=\.js$)/, '.min'); | destPath = srcPath.replace(/(?=\.js$)/, '.min'); | |||
} | } | |||
var output = uglify.minify(inpath, _.defaults(options || {}, uglifyOptions)); | const output = uglify.minify(srcPath, _.defaults(options || {}, uglifyOptions) | |||
fs.writeFile(outpath, output.code, 'utf-8', callback); | ); | |||
fs.writeFile(destPath, output.code, 'utf-8', callback); | ||||
} | } | |||
module.exports = minify; | module.exports = minify; | |||
End of changes. 6 change blocks. | ||||
12 lines changed or deleted | 27 lines changed or added |