|
@@ -1,7 +1,54 @@
|
|
|
|
|
+import { gzipSync } from 'zlib';
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
import resolve from '@rollup/plugin-node-resolve';
|
|
|
-import filesize from 'rollup-plugin-filesize';
|
|
|
|
|
import terser from '@rollup/plugin-terser';
|
|
import terser from '@rollup/plugin-terser';
|
|
|
|
|
|
|
|
|
|
+function filesize() {
|
|
|
|
|
+
|
|
|
|
|
+ const green = '\x1b[1m\x1b[32m';
|
|
|
|
|
+ const yellow = '\x1b[33m';
|
|
|
|
|
+ const reset = '\x1b[0m';
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ name: 'filesize',
|
|
|
|
|
+ writeBundle( options, bundle ) {
|
|
|
|
|
+
|
|
|
|
|
+ for ( const [ , chunk ] of Object.entries( bundle ) ) {
|
|
|
|
|
+
|
|
|
|
|
+ if ( chunk.code ) {
|
|
|
|
|
+
|
|
|
|
|
+ const size = ( chunk.code.length / 1024 ).toFixed( 2 ) + ' KB';
|
|
|
|
|
+ const gzipped = ( gzipSync( chunk.code ).length / 1024 ).toFixed( 2 ) + ' KB';
|
|
|
|
|
+ const destination = options.file;
|
|
|
|
|
+
|
|
|
|
|
+ const lines = [
|
|
|
|
|
+ { label: 'Destination: ', value: destination },
|
|
|
|
|
+ { label: 'Bundle Size: ', value: size },
|
|
|
|
|
+ { label: 'Gzipped Size: ', value: gzipped }
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ const maxLength = Math.max( ...lines.map( l => l.label.length + l.value.length ) );
|
|
|
|
|
+ const width = maxLength + 6;
|
|
|
|
|
+
|
|
|
|
|
+ console.log( `\n┌${'─'.repeat( width )}┐` );
|
|
|
|
|
+ console.log( `│${' '.repeat( width )}│` );
|
|
|
|
|
+ lines.forEach( ( { label, value } ) => {
|
|
|
|
|
+
|
|
|
|
|
+ const padding = ' '.repeat( width - label.length - value.length - 3 );
|
|
|
|
|
+ console.log( `│ ${green}${label}${yellow}${value}${reset}${padding}│` );
|
|
|
|
|
+
|
|
|
|
|
+ } );
|
|
|
|
|
+ console.log( `│${' '.repeat( width )}│` );
|
|
|
|
|
+ console.log( `└${'─'.repeat( width )}┘` );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
export default [
|
|
export default [
|
|
|
{
|
|
{
|
|
|
input: 'test/treeshake/index.js',
|
|
input: 'test/treeshake/index.js',
|
|
@@ -20,9 +67,7 @@ export default [
|
|
|
plugins: [
|
|
plugins: [
|
|
|
resolve(),
|
|
resolve(),
|
|
|
terser(),
|
|
terser(),
|
|
|
- filesize( {
|
|
|
|
|
- showMinifiedSize: false,
|
|
|
|
|
- } )
|
|
|
|
|
|
|
+ filesize()
|
|
|
],
|
|
],
|
|
|
output: [
|
|
output: [
|
|
|
{
|
|
{
|
|
@@ -48,9 +93,7 @@ export default [
|
|
|
plugins: [
|
|
plugins: [
|
|
|
resolve(),
|
|
resolve(),
|
|
|
terser(),
|
|
terser(),
|
|
|
- filesize( {
|
|
|
|
|
- showMinifiedSize: false,
|
|
|
|
|
- } )
|
|
|
|
|
|
|
+ filesize()
|
|
|
],
|
|
],
|
|
|
output: [
|
|
output: [
|
|
|
{
|
|
{
|
|
@@ -76,9 +119,7 @@ export default [
|
|
|
plugins: [
|
|
plugins: [
|
|
|
resolve(),
|
|
resolve(),
|
|
|
terser(),
|
|
terser(),
|
|
|
- filesize( {
|
|
|
|
|
- showMinifiedSize: false,
|
|
|
|
|
- } )
|
|
|
|
|
|
|
+ filesize()
|
|
|
],
|
|
],
|
|
|
output: [
|
|
output: [
|
|
|
{
|
|
{
|