From 1c6d118169a504a005710c97ff7dd1f5adfb34a9 Mon Sep 17 00:00:00 2001 From: Dom Charlesworth Date: Fri, 9 Jun 2017 16:13:29 +0100 Subject: [PATCH] Add in post build step to minify code using UglifyJS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I tried to use a couple of things integrated directly with babel, + https://github.com/babel/babili - Issue with es2015 preset babel/babili#556 + https://github.com/rreverser/babel-plugin-uglify - Just didn't work! So, added in a script using the UglifyJS2 CLI tool which saves ~20% of the size! ✌ --- package.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f65b87e..03c507a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "uStyle React Components", "main": "dist/index.js", "scripts": { - "build": "rm -rf dist; babel src --out-dir dist", + "build": "rm -rf dist; babel src --out-dir dist; echo Pre-Minify: `du -sh dist | cut -f1`", + "postbuild": "find dist -type f -exec uglifyjs {} --mangle --compress -o {} \\;; echo Post-Minify: `du -sh dist | cut -f1`", "start": "webpack-dev-server", "commit-dist": "npm run build; npm run lint:fix; git add dist", "bump-version": "nver; git add package.json", @@ -34,8 +35,6 @@ "react": ">=15.3" }, "devDependencies": { - "react": ">=15.3", - "react-dom": ">=15.3", "babel-cli": "^6.24.0", "babel-core": "^6.24.0", "babel-loader": "^6.4.1", @@ -44,8 +43,11 @@ "nodemon": "^1.11.0", "nver": "^0.0.15", "pre-commit": "^1.2.2", + "react": ">=15.3", + "react-dom": ">=15.3", "standard": "^10.0.2", + "uglify-js": "^3.0.15", "webpack": "^2.3.3", "webpack-dev-server": "^2.4.2" } -} \ No newline at end of file +}