diff --git a/packages/standard-minifiers/plugin/minify-css.js b/packages/standard-minifiers/plugin/minify-css.js index 1c78ada886..87edeeeeeb 100644 --- a/packages/standard-minifiers/plugin/minify-css.js +++ b/packages/standard-minifiers/plugin/minify-css.js @@ -42,7 +42,7 @@ var mergeCss = function (css) { var originals = {}; var cssAsts = css.map(function (file) { - var filename = file.getPathInPackage(); + var filename = file.getPathInBundle(); originals[filename] = file; try { var parseOptions = { source: filename, position: true }; diff --git a/packages/standard-minifiers/plugin/minify-js.js b/packages/standard-minifiers/plugin/minify-js.js index 34fa8cf95b..9f7487277a 100644 --- a/packages/standard-minifiers/plugin/minify-js.js +++ b/packages/standard-minifiers/plugin/minify-js.js @@ -14,7 +14,7 @@ UglifyJSMinifier.prototype.processFilesForTarget = function (files, mode) { file.addJavaScript({ data: file.getContentsAsBuffer(), sourceMap: file.getSourceMap(), - path: file.getPathInPackage() + path: file.getPathInBundle() }); }); return; diff --git a/tools/minifier-plugin.js b/tools/minifier-plugin.js index ac83dd53b0..90f923a747 100644 --- a/tools/minifier-plugin.js +++ b/tools/minifier-plugin.js @@ -1,86 +1,75 @@ -var buildPluginModule = require('./build-plugin.js'); -var util = require('util'); -var _ = require('underscore'); +import buildPluginModule from './build-plugin.js'; -var InputFile = exports.InputFile = function (source, options) { - buildPluginModule.InputFile.call(this); +class InputFile extends buildPluginModule.InputFile { + constructor(source, options = {}) { + super(); - var self = this; - options = options || {}; + this._source = source; + this._arch = options.arch; + this._minifiedFiles = []; + } - self._source = source; - self._arch = options.arch; - self._minifiedFiles = []; -}; - -util.inherits(InputFile, buildPluginModule.InputFile); - -_.extend(InputFile.prototype, { - getContentsAsBuffer: function () { + getContentsAsBuffer() { return this._source.contents(); - }, - getPathInPackage: function () { - return this._source.targetPath; - }, - getPackageName: function () { + } + getPathInPackage() { throw new Error("Compiled files don't belong to any package"); - }, - getSourceHash: function () { + } + getPackageName() { + throw new Error("Compiled files don't belong to any package"); + } + getSourceHash() { return this._source.hash(); - }, - getArch: function () { + } + getArch() { return this._arch; - }, + } + + /** + * @summary Returns the path of the compiled file in the bundle. + * @memberof InputFile + * @returns {String} + */ + getPathInBundle() { + return this._source.targetPath; + } /** * @summary Returns the source-map associated with the file. * @memberof InputFile * @returns {String} */ - getSourceMap: function () { + getSourceMap() { return this._source.sourceMap; } -}); +} -var JsFile = exports.JsFile = function (source, options) { - InputFile.apply(this, arguments); -}; - -util.inherits(JsFile, InputFile); - -_.extend(JsFile.prototype, { +export class JsFile extends InputFile { // - data // - sourceMap // - path // - hash? - addJavaScript: function (options) { - var self = this; + addJavaScript(options) { + const self = this; self._minifiedFiles.push({ data: options.data, sourceMap: options.sourceMap, path: options.path }); } -}); +} -var CssFile = exports.CssFile = function (source, options) { - InputFile.apply(this, arguments); -}; - -util.inherits(CssFile, InputFile); - -_.extend(CssFile.prototype, { +export class CssFile extends InputFile { // - data // - sourceMap // - path // - hash? - addStylesheet: function (options) { - var self = this; - self._minifiedFiles.push({ + addStylesheet(options) { + this._minifiedFiles.push({ data: options.data, sourceMap: options.sourceMap, path: options.path }); } -}); +}