Skip to content

Commit

Permalink
updated build script to minify with terser
Browse files Browse the repository at this point in the history
  • Loading branch information
getify committed Jan 7, 2019
1 parent b2dae89 commit 44ce507
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -403,7 +403,7 @@ The distribution library file (`dist/caf.js`) comes pre-built with the npm packa

However, if you download this repository via Git:

1. The included build utility (`scripts/build-core.js`) builds (and ~~minifies~~) `dist/caf.js` from source. **Note:** Minification is currently disabled. **The build utility expects Node.js version 6+.**
1. The included build utility (`scripts/build-core.js`) builds (and minifies) `dist/caf.js` from source. **The build utility expects Node.js version 6+.**

2. To install the build and test dependencies, run `npm install` from the project root directory.

Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "caf",
"version": "7.0.4",
"version": "7.0.5",
"description": "Cancelable Async Flows: a wrapper to treat generators as cancelable async functions",
"main": "./dist/caf.js",
"scripts": {
Expand All @@ -18,7 +18,8 @@
},
"devDependencies": {
"coveralls": "~3.0.0",
"qunit": "~2.6.0"
"qunit": "~2.6.0",
"terser": "~3.14.1"
},
"repository": "getify/caf",
"keywords": [
Expand Down
36 changes: 20 additions & 16 deletions scripts/build-core.js
Expand Up @@ -2,7 +2,7 @@

var fs = require("fs"),
path = require("path"),
// ugly = require("uglify-js"),
ugly = require("terser"),
packageJSON,
copyrightHeader,
version,
Expand Down Expand Up @@ -31,21 +31,25 @@ try {
catch (err) { }

result += fs.readFileSync(POLYFILL_SRC,{ encoding: "utf8" });
result += "\n" + fs.readFileSync(CORE_SRC,{ encoding: "utf8" });
result += `\n${fs.readFileSync(CORE_SRC,{ encoding: "utf8" })}`;

// NOTE: since uglify doesn't yet support ES6, no minifying happening :(
result = ugly.minify(result,{
mangle: {
keep_fnames: true
},
compress: {
keep_fnames: true
},
output: {
comments: /^!/
}
});

// result = ugly.minify(path.join(SRC_DIR,"caf.src.js"),{
// mangle: {
// keep_fnames: true
// },
// compress: {
// keep_fnames: true
// },
// output: {
// comments: /^!/
// }
// });
// was compression successful?
if (!(result && result.code)) {
if (result.error) throw result.error;
else throw result;
}

// read version number from package.json
packageJSON = JSON.parse(
Expand All @@ -64,10 +68,10 @@ try {
copyrightHeader = Function("version","year",`return \`${copyrightHeader}\`;`)( version, year );

// append copyright-header text
result = copyrightHeader + result;
result = `${copyrightHeader}${result.code}`;

// write dist
fs.writeFileSync( CORE_DIST, result /* result.code + "\n" */, { encoding: "utf8" } );
fs.writeFileSync( CORE_DIST, result, { encoding: "utf8" } );

console.log("Complete.");
}
Expand Down

0 comments on commit 44ce507

Please sign in to comment.