Skip to content

Commit

Permalink
Added a build step to minify the browser version of the Dompiler Java…
Browse files Browse the repository at this point in the history
…Script files.
  • Loading branch information
Nicholas-Westby committed Jun 30, 2019
1 parent c36a00d commit 76fe2ff
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
19 changes: 18 additions & 1 deletion src/build.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Dependencies.
let fs = require("fs");
let fs = require("fs"),
Terser = require("terser");

// Variables.
let noop = function () {};
Expand All @@ -12,6 +13,10 @@ transformExports("library/events.js", "dist/events.js");
fs.copyFile("library/dompiler.js", "../docs/library/dompiler.js", noop);
fs.copyFile("library/events.js", "../docs/library/events.js", noop);

// Minify the files.
minifyFile("library/dompiler.js", "dist/browser/dompiler.min.js");
minifyFile("library/events.js", "dist/browser/events.min.js");

/**
* Converts the specified file into one that uses the type of exports
* that Node understands.
Expand All @@ -23,4 +28,16 @@ function transformExports(inFilename, outFilename) {
data = data.replace("export default", "module.exports =");
fs.writeFile(outFilename, data, noop);
});
}

/**
* Minifies the specified JavaScript file.
* @param inFilename The path to the JavaScript file to minify.
* @param outFilename The path to the file to save the minified code to.
*/
function minifyFile(inFilename, outFilename) {
fs.readFile(inFilename, "utf8", function (err, data) {
let result = Terser.minify(data);
fs.writeFile(outFilename, result.code, noop);
});
}
1 change: 1 addition & 0 deletions src/dist/browser/dompiler.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/dist/browser/events.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 44 additions & 2 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
"bugs": {
"url": "https://github.com/Nicholas-Westby/dompiler/issues"
},
"homepage": "https://www.dompiler.com/"
"homepage": "https://www.dompiler.com/",
"devDependencies": {
"terser": "^4.0.1"
}
}

0 comments on commit 76fe2ff

Please sign in to comment.