Skip to content

Commit

Permalink
Move to uglify-es and rollup-plugin-uglify@3!
Browse files Browse the repository at this point in the history
  • Loading branch information
developit committed Jan 26, 2018
1 parent 6a06939 commit cc87186
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -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",
Expand Down
55 changes: 31 additions & 24 deletions src/index.js
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
} },
Expand Down

0 comments on commit cc87186

Please sign in to comment.