Skip to content

Commit 6bab8bd

Browse files
authored
test-treeshake: Add rollup-plugin-visualizer (mrdoob#21657)
1 parent cd573e2 commit 6bab8bd

File tree

6 files changed

+196
-27
lines changed

6 files changed

+196
-27
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ test/*.cmd
2020
test/unit/build
2121
test/treeshake/index.bundle.js
2222
test/treeshake/index.bundle.min.js
23+
test/treeshake/index-src.bundle.min.js
24+
test/treeshake/stats.html
2325

2426

2527
**/node_modules

package-lock.json

+126-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"@babel/preset-env": "^7.13.12",
9797
"@rollup/plugin-babel": "^5.3.0",
9898
"@rollup/plugin-node-resolve": "^11.2.1",
99+
"chalk": "^4.1.0",
99100
"concurrently": "^6.0.0",
100101
"eslint": "^7.23.0",
101102
"eslint-config-mdcs": "^5.0.0",
@@ -104,6 +105,7 @@
104105
"rollup": "^2.44.0",
105106
"rollup-plugin-filesize": "^9.1.1",
106107
"rollup-plugin-terser": "^7.0.2",
108+
"rollup-plugin-visualizer": "^5.3.6",
107109
"servez": "^1.11.0"
108110
},
109111
"jspm": {

test/rollup.treeshake.config.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1+
import path from 'path';
12
import resolve from '@rollup/plugin-node-resolve';
23
import filesize from 'rollup-plugin-filesize';
34
import { terser } from 'rollup-plugin-terser';
5+
import { visualizer } from 'rollup-plugin-visualizer';
6+
import { glconstants, glsl } from '../utils/build/rollup.config';
7+
import chalk from 'chalk';
8+
9+
const statsFile = path.resolve( __dirname, './treeshake/stats.html' );
10+
11+
function logStatsFile() {
12+
13+
return {
14+
writeBundle() {
15+
16+
console.log();
17+
console.log( 'Open the following url in a browser to analyze the tree-shaken bundle.' );
18+
console.log( chalk.blue.bold.underline( statsFile ) );
19+
console.log();
20+
21+
}
22+
};
23+
24+
}
425

526
export default [
627
{
@@ -30,5 +51,23 @@ export default [
3051
file: 'test/treeshake/index.bundle.min.js'
3152
}
3253
]
33-
}
54+
},
55+
{
56+
input: 'test/treeshake/index-src.js',
57+
plugins: [
58+
glconstants(),
59+
glsl(),
60+
terser(),
61+
visualizer( {
62+
filename: statsFile,
63+
} ),
64+
logStatsFile(),
65+
],
66+
output: [
67+
{
68+
format: 'esm',
69+
file: 'test/treeshake/index-src.bundle.min.js'
70+
}
71+
]
72+
},
3473
];

test/treeshake/index-src.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as THREE from '../../src/Three.js';
2+
3+
let camera, scene, renderer;
4+
5+
init();
6+
7+
function init() {
8+
9+
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 10 );
10+
11+
scene = new THREE.Scene();
12+
13+
renderer = new THREE.WebGLRenderer( { antialias: true } );
14+
renderer.setSize( window.innerWidth, window.innerHeight );
15+
renderer.setAnimationLoop( animation );
16+
document.body.appendChild( renderer.domElement );
17+
18+
}
19+
20+
function animation( ) {
21+
22+
renderer.render( scene, camera );
23+
24+
}

utils/build/rollup.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import babel from '@rollup/plugin-babel';
22
import { terser } from 'rollup-plugin-terser';
33
import babelrc from './.babelrc.json';
44

5-
function glconstants() {
5+
export function glconstants() {
66

77
var constants = {
88
POINTS: 0, ZERO: 0, NONE: 0,
@@ -200,7 +200,7 @@ function addons() {
200200

201201
}
202202

203-
function glsl() {
203+
export function glsl() {
204204

205205
return {
206206

0 commit comments

Comments
 (0)