rollup-plugin-filesize
Advanced tools
Comparing version 0.1.1 to 0.2.1
@@ -8,2 +8,3 @@ 'use strict'; | ||
var Chalk = _interopDefault(require('chalk')); | ||
var _ = _interopDefault(require('lodash')); | ||
@@ -13,9 +14,26 @@ var chalk = new Chalk.constructor({ enabled: true }); | ||
function filesize() { | ||
return { | ||
transformBundle: function transformBundle(code) { | ||
console.log(boxen(chalk.green.bold('Bundle size : ') + chalk.yellow.bold(fileSize(Buffer.byteLength(code))), { padding: 1 })); | ||
} | ||
}; | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
return { | ||
transformBundle: function transformBundle(code) { | ||
var defaultOptions = { | ||
format: {}, | ||
theme: 'dark', | ||
render: render | ||
}; | ||
var opts = _.defaultsDeep(options, defaultOptions); | ||
function render(size) { | ||
return opts.theme == 'dark' ? boxen(chalk.green.bold('Bundle size : ') + chalk.yellow.bold(size), { padding: 1 }) : boxen(chalk.black.bold('Bundle size : ') + chalk.blue.bold(size), { padding: 1 }); | ||
} | ||
var size = fileSize(Buffer.byteLength(code), opts.format); | ||
console.log(opts.render(size)); | ||
} | ||
}; | ||
}; | ||
module.exports = filesize; |
{ | ||
"name": "rollup-plugin-filesize", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"description": "A rollup plugin to show filesize in the cli", | ||
"main": "dist/index.js", | ||
"jsnext:main" : "src/index.js", | ||
"jsnext:main": "src/index.js", | ||
"scripts": { | ||
@@ -28,3 +28,4 @@ "test": "echo \"Error: no test specified\" && exit 1", | ||
"chalk": "^1.1.1", | ||
"filesize": "^3.2.0" | ||
"filesize": "^3.2.0", | ||
"lodash": "^4.0.1" | ||
}, | ||
@@ -31,0 +32,0 @@ "devDependencies": { |
@@ -25,4 +25,37 @@ # rollup-pugin-filesize | ||
## options | ||
#### format | ||
type : `object` | ||
default : {} | ||
See the options [here](https://github.com/avoidwork/filesize.js) | ||
#### render | ||
type : `function` | ||
return the command that you want to log. Eg: | ||
```js | ||
filesize( | ||
render : function (size){ | ||
return size; | ||
} | ||
) | ||
``` | ||
#### theme | ||
type: `string` | ||
default : 'dark' | ||
options : 'dark'/'light' | ||
choose based on your terminal theme. | ||
## License | ||
MIT | ||
import babel from 'rollup-plugin-babel'; | ||
export default { | ||
external: [ 'filesize', 'boxen', 'chalk' ], | ||
external: [ 'filesize', 'boxen', 'chalk', 'lodash' ], | ||
plugins: [ | ||
@@ -6,0 +6,0 @@ babel({ |
import fileSize from 'filesize'; | ||
import boxen from 'boxen'; | ||
import Chalk from 'chalk'; | ||
import _ from 'lodash'; | ||
var chalk = new Chalk.constructor({enabled:true}); | ||
export default function filesize(){ | ||
export default function filesize(options = {}){ | ||
return { | ||
transformBundle(code){ | ||
console.log(boxen(chalk.green.bold('Bundle size : ') + chalk.yellow.bold(fileSize(Buffer.byteLength(code))), {padding:1})); | ||
let defaultOptions = { | ||
format:{}, | ||
theme : 'dark', | ||
render:render | ||
}; | ||
let opts = _.defaultsDeep(options, defaultOptions); | ||
function render(size){ | ||
return opts.theme == 'dark' ? ( | ||
boxen(chalk.green.bold('Bundle size : ') + chalk.yellow.bold(size), { padding: 1 }) | ||
) : ( | ||
boxen(chalk.black.bold('Bundle size : ') + chalk.blue.bold(size), { padding: 1 }) | ||
); | ||
} | ||
let size = fileSize(Buffer.byteLength(code), opts.format); | ||
console.log(opts.render(size)) | ||
} | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4733
63
61
4
+ Addedlodash@^4.0.1
+ Addedlodash@4.17.21(transitive)