rollup-plugin-uglify
Advanced tools
Comparing version 0.1.0 to 0.2.0
'use strict'; | ||
var uglify = require('uglify-js'); | ||
uglify = 'default' in uglify ? uglify['default'] : uglify; | ||
function _interopDefault (ex) { return 'default' in ex ? ex['default'] : ex; } | ||
var uglify = _interopDefault(require('uglify-js')); | ||
function index () { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
return { | ||
transformBundle: function transformBundle(code) { | ||
var uglifyOptions = { | ||
fromString: true | ||
}; | ||
return { | ||
transformBundle: function transformBundle(code) { | ||
options.fromString = true; | ||
delete options.inSourceMap; | ||
delete options.outSourceMap; | ||
// trigger sourcemap generation | ||
if (options.sourceMap !== false) { | ||
uglifyOptions.outSourceMap = 'x'; | ||
} | ||
// trigger sourcemap generation | ||
if (options.sourceMap !== false) { | ||
options.outSourceMap = 'x'; | ||
} | ||
var result = uglify.minify(code, uglifyOptions); | ||
var result = uglify.minify(code, options); | ||
// Strip sourcemaps comment and extra \n | ||
if (result.map) { | ||
var commentPos = result.code.lastIndexOf('//#'); | ||
result.code = result.code.slice(0, commentPos).trim(); | ||
} | ||
// Strip sourcemaps comment and extra \n | ||
if (result.map) { | ||
var commentPos = result.code.lastIndexOf('//#'); | ||
result.code = result.code.slice(0, commentPos).trim(); | ||
} | ||
return result; | ||
} | ||
}; | ||
return result; | ||
} | ||
}; | ||
} | ||
module.exports = index; |
{ | ||
"name": "rollup-plugin-uglify", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Rollup plugin to minify generated bundle", | ||
@@ -11,3 +11,3 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build": "rollup -c -f cjs -o dist/index.js", | ||
"lint": "eslint src test/*.js", | ||
@@ -18,2 +18,5 @@ "pretest": "npm run lint && npm run build", | ||
}, | ||
"eslintConfig": { | ||
"extends": "postcss" | ||
}, | ||
"repository": { | ||
@@ -39,9 +42,9 @@ "type": "git", | ||
"devDependencies": { | ||
"ava": "^0.9.1", | ||
"babel-eslint": "^4.1.6", | ||
"babel-preset-es2015-rollup": "^1.0.0", | ||
"ava": "^0.11.0", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"eslint": "^1.10.3", | ||
"rollup": "^0.23.1", | ||
"rollup-plugin-babel": "^2.3.2" | ||
"eslint-config-postcss": "^1.0.0", | ||
"rollup": "^0.25.2", | ||
"rollup-plugin-babel": "^2.3.9" | ||
} | ||
} |
import uglify from 'uglify-js'; | ||
export default function (options = {}) { | ||
return { | ||
transformBundle(code) { | ||
let uglifyOptions = { | ||
fromString: true | ||
}; | ||
return { | ||
transformBundle(code) { | ||
options.fromString = true; | ||
delete options.inSourceMap; | ||
delete options.outSourceMap; | ||
// trigger sourcemap generation | ||
if (options.sourceMap !== false) { | ||
uglifyOptions.outSourceMap = 'x'; | ||
} | ||
// trigger sourcemap generation | ||
if (options.sourceMap !== false) { | ||
options.outSourceMap = 'x'; | ||
} | ||
let result = uglify.minify(code, uglifyOptions); | ||
const result = uglify.minify(code, options); | ||
// Strip sourcemaps comment and extra \n | ||
if (result.map) { | ||
let commentPos = result.code.lastIndexOf('//#'); | ||
result.code = result.code.slice(0, commentPos).trim(); | ||
} | ||
// Strip sourcemaps comment and extra \n | ||
if (result.map) { | ||
const commentPos = result.code.lastIndexOf('//#'); | ||
result.code = result.code.slice(0, commentPos).trim(); | ||
} | ||
return result; | ||
} | ||
}; | ||
return result; | ||
} | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
4476