From cc8718638c7345e8738292e912f40c65a309505a Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 26 Jan 2018 12:49:55 -0500 Subject: [PATCH] Move to `uglify-es` and `rollup-plugin-uglify@3`! --- package.json | 5 ++--- src/index.js | 55 +++++++++++++++++++++++++++++----------------------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 0843c545..90d6ee2f 100644 --- a/package.json +++ b/package.json @@ -61,10 +61,9 @@ "rollup-plugin-sizes": "^0.4.2", "rollup-plugin-strict-alias": "^1.0.0", "rollup-plugin-typescript": "^0.8.1", - "rollup-plugin-uglify": "^2.0.1", + "rollup-plugin-uglify": "^3.0.0", "sade": "^1.3.1", - "typescript": "^2.6.2", - "uglify-es": "^3.3.8" + "typescript": "^2.6.2" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/src/index.js b/src/index.js index a93edc03..821222ac 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,6 @@ import typescript from 'rollup-plugin-typescript'; import flow from './lib/flow-plugin'; import camelCase from 'camelcase'; -const interopRequire = m => m.default || m; const readFile = promisify(fs.readFile); const stat = promisify(fs.stat); const isDir = name => stat(name).then( stats => stats.isDirectory() ).catch( () => false ); @@ -259,32 +258,40 @@ function createConfig(options, entry, format, writeMeta) { // [`export default ${rollupName};`]: '', // [`var ${rollupName} =`]: 'export default' // }), - options.compress!==false && uglify({ - output: { comments: false }, - mangle: { + options.compress!==false && [ + uglify({ + output: { comments: false }, + compress: { + keep_infinity: true, + pure_getters: true + }, + warnings: true, + ecma: 5, toplevel: format==='cjs' || format==='es', - properties: mangleOptions ? { - regex: mangleOptions.regex ? new RegExp(mangleOptions.regex) : null, - reserved: mangleOptions.reserved || [] - } : false - }, - nameCache - }, format==='es' ? interopRequire(require('uglify-es')).minify : undefined), - mangleOptions && { - // before hook - options() { - try { - nameCache = JSON.parse(fs.readFileSync(resolve(options.cwd, 'mangle.json'), 'utf8')); - } - catch (e) {} - }, - // after hook - onwrite() { - if (writeMeta && nameCache) { - fs.writeFile(resolve(options.cwd, 'mangle.json'), JSON.stringify(nameCache, null, 2), Object); + mangle: { + properties: mangleOptions ? { + regex: mangleOptions.regex ? new RegExp(mangleOptions.regex) : null, + reserved: mangleOptions.reserved || [] + } : false + }, + nameCache + }), + mangleOptions && { + // before hook + options() { + try { + nameCache = JSON.parse(fs.readFileSync(resolve(options.cwd, 'mangle.json'), 'utf8')); + } + catch (e) {} + }, + // after hook + onwrite() { + if (writeMeta && nameCache) { + fs.writeFile(resolve(options.cwd, 'mangle.json'), JSON.stringify(nameCache, null, 2), Object); + } } } - }, + ], { ongenerate({ bundle }, { code }) { config._code = bundle._code = code; } },