Skip to content

Commit cea103a

Browse files
committed
test: add tree-shaking test
currently this doesn't throw or break the build, first we need to resolve all of the existing issues. to run execute: ./tools/tree-shaking-test/test.sh then inspect dist/tree-shaking/test/**/*.bundle.js
1 parent d18694a commit cea103a

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

tools/tree-shaking-test/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Rollup tree-shaking test
2+
------------------------
3+
4+
The purpose of this test is to verify how much stuff can be tree-shaken from our packages.
5+
6+
The test generates an empty js file that imports everything from a particular package but doesn't
7+
use any of the imported references.
8+
9+
In the ideal scenario Rollup should detect that none of the references are being used and should
10+
create an empty bundle file.
11+
12+
In reality there is a lot of stuff preserved in the bundle because Rollup is currently not able to
13+
make a safe decision to remove many of the unused symbols.
14+
15+
To run execute: `./tools/tree-shaking-test/test.sh`
16+
17+
then inspect `dist/tree-shaking/test/**/*.bundle.js`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class RollupNG2 {
2+
resolveId(id, from){
3+
if(id.startsWith('@angular/')){
4+
return `${__dirname}/../../packages-dist/${id.split('/')[1]}/esm/index.js`;
5+
}
6+
7+
// if(id.startsWith('rxjs/')){
8+
// return `${__dirname}/../../../node_modules/rxjs-es/${id.replace('rxjs/', '')}.js`;
9+
// }
10+
}
11+
}
12+
13+
14+
export default {
15+
entry: 'test.js',
16+
format: 'es6',
17+
plugins: [
18+
new RollupNG2(),
19+
]
20+
}

tools/tree-shaking-test/test.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex -o pipefail
4+
5+
cd `dirname $0`
6+
cd ../..
7+
8+
export NODE_PATH=${NODE_PATH}:$(pwd)/dist-packages/
9+
10+
DEST_DIR=./dist/trees-shaking-test
11+
12+
rm -rf ${DEST_DIR}
13+
14+
for PACKAGE in \
15+
core \
16+
compiler \
17+
common \
18+
platform-browser \
19+
platform-server \
20+
http \
21+
router \
22+
upgrade
23+
do
24+
echo "======= Tree-shaking TEST: ${SRCDIR} ====="
25+
TEST_DIR=${DEST_DIR}/${PACKAGE}
26+
TEST_ENTRY_POINT=${TEST_DIR}/test.js
27+
mkdir -p ${TEST_DIR}
28+
cp ./tools/tree-shaking-test/rollup.config.js ${TEST_DIR}/
29+
echo "import * as x from '@angular/${PACKAGE}'" > ${TEST_ENTRY_POINT}
30+
(
31+
cd ${TEST_DIR}
32+
$(npm bin)/rollup --config rollup.config.js --output ${PACKAGE}.bundle.js
33+
)
34+
35+
done

0 commit comments

Comments
 (0)