Skip to content

Commit

Permalink
test-treeshake: Add rollup-plugin-visualizer (mrdoob#21657)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro authored Apr 15, 2021
1 parent cd573e2 commit 6bab8bd
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test/*.cmd
test/unit/build
test/treeshake/index.bundle.js
test/treeshake/index.bundle.min.js
test/treeshake/index-src.bundle.min.js
test/treeshake/stats.html


**/node_modules
150 changes: 126 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@babel/preset-env": "^7.13.12",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"chalk": "^4.1.0",
"concurrently": "^6.0.0",
"eslint": "^7.23.0",
"eslint-config-mdcs": "^5.0.0",
Expand All @@ -104,6 +105,7 @@
"rollup": "^2.44.0",
"rollup-plugin-filesize": "^9.1.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.3.6",
"servez": "^1.11.0"
},
"jspm": {
Expand Down
41 changes: 40 additions & 1 deletion test/rollup.treeshake.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import filesize from 'rollup-plugin-filesize';
import { terser } from 'rollup-plugin-terser';
import { visualizer } from 'rollup-plugin-visualizer';
import { glconstants, glsl } from '../utils/build/rollup.config';
import chalk from 'chalk';

const statsFile = path.resolve( __dirname, './treeshake/stats.html' );

function logStatsFile() {

return {
writeBundle() {

console.log();
console.log( 'Open the following url in a browser to analyze the tree-shaken bundle.' );
console.log( chalk.blue.bold.underline( statsFile ) );
console.log();

}
};

}

export default [
{
Expand Down Expand Up @@ -30,5 +51,23 @@ export default [
file: 'test/treeshake/index.bundle.min.js'
}
]
}
},
{
input: 'test/treeshake/index-src.js',
plugins: [
glconstants(),
glsl(),
terser(),
visualizer( {
filename: statsFile,
} ),
logStatsFile(),
],
output: [
{
format: 'esm',
file: 'test/treeshake/index-src.bundle.min.js'
}
]
},
];
24 changes: 24 additions & 0 deletions test/treeshake/index-src.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as THREE from '../../src/Three.js';

let camera, scene, renderer;

init();

function init() {

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );

scene = new THREE.Scene();

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animation );
document.body.appendChild( renderer.domElement );

}

function animation( ) {

renderer.render( scene, camera );

}
4 changes: 2 additions & 2 deletions utils/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import babelrc from './.babelrc.json';

function glconstants() {
export function glconstants() {

var constants = {
POINTS: 0, ZERO: 0, NONE: 0,
Expand Down Expand Up @@ -200,7 +200,7 @@ function addons() {

}

function glsl() {
export function glsl() {

return {

Expand Down

0 comments on commit 6bab8bd

Please sign in to comment.