Skip to content

Commit 7000b1b

Browse files
committed
refactor: improve tree shaking abilities
Internal refactor completed in order to improve tree shaking and dead code removal. The public API, with an exception to ion-slides, has stayed the same. However, internally many changes were required so bundlers could better exclude modules which should not be bundled. Ultimately most changes resorted to removing references to `window` or `document`, or a module that referenced one of those. BREAKING CHANGES ion-slides was refactored to remove the external dependencies, and rewritten in TypeScript/ES6 modules to again improve tree shaking abilities.
1 parent 13cf6a6 commit 7000b1b

File tree

191 files changed

+9340
-13603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+9340
-13603
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"karma-coverage": "1.1.1",
103103
"karma-jasmine": "1.0.2",
104104
"karma-sourcemap-loader": "0.3.7",
105+
"karma-spec-reporter": "0.0.26",
105106
"merge2": "1.0.2",
106107
"mkdirp": "0.5.1",
107108
"node-html-encoder": "0.0.2",

scripts/demos/demos.template.dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
}
3737
});
3838
</script>
39-
<script src="../polyfills/polyfills.ng.js"></script>
39+
<script src="../polyfills/polyfills.js"></script>
4040
<script src="../../bundles/ionic.system.js"></script>
4141
</head>
4242

scripts/demos/demos.template.prod.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ion-app></ion-app>
1515

16-
<script src="../polyfills/polyfills.ng.js"></script>
16+
<script src="../polyfills/polyfills.js"></script>
1717
<script src="./build/main.js"></script>
1818
</body>
1919
</html>

scripts/gulp/tasks/build.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { task } from 'gulp';
22
import { DIST_BUILD_ROOT, DIST_BUILD_ES2015_ROOT, DIST_BUILD_UMD_ROOT, ES5, ES_2015, PROJECT_ROOT, UMD_MODULE } from '../constants';
3-
import { copySourceToDest, copySwiperToPath, createTempTsConfig, deleteFiles, runNgc } from '../util';
3+
import { copySourceToDest, createTempTsConfig, deleteFiles, runNgc } from '../util';
44

55

66
export function buildIonicAngularUmd(excludeSpec: boolean, stripDebug: boolean, done: Function) {
@@ -14,7 +14,6 @@ export function buildIonicAngularUmd(excludeSpec: boolean, stripDebug: boolean,
1414
return;
1515
}
1616

17-
copySwiperToPath(`${DIST_BUILD_UMD_ROOT}/components/slides`, UMD_MODULE);
1817
// clean up any .ts files that remain as well as ngc metadata
1918
deleteFiles([`${DIST_BUILD_UMD_ROOT}/**/*.ts`,
2019
`${DIST_BUILD_UMD_ROOT}/node_modules`,
@@ -34,7 +33,6 @@ export function buildIonicAngularEsm(stripDebug: boolean, done: Function) {
3433
done(err);
3534
return;
3635
}
37-
copySwiperToPath(`${DIST_BUILD_ROOT}/components/slides`, ES_2015);
3836
// clean up any .ts files that remain as well as ngc metadata
3937
deleteFiles([`${DIST_BUILD_ROOT}/**/*.ts`,
4038
`${DIST_BUILD_ROOT}/node_modules`,
@@ -54,7 +52,6 @@ export function buildIonicPureEs6(stripDebug: boolean, done: Function) {
5452
done(err);
5553
return;
5654
}
57-
copySwiperToPath(`${DIST_BUILD_ES2015_ROOT}/components/slides`, ES_2015);
5855
// clean up any .ts files that remain as well as ngc metadata
5956
deleteFiles([`${DIST_BUILD_ES2015_ROOT}/**/*.ts`,
6057
`${DIST_BUILD_ES2015_ROOT}/node_modules`,

scripts/gulp/tasks/clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ task('clean', (done: Function) => {
1010
});
1111

1212
task('clean.src', (done: Function) => {
13-
del(['src/**/*.js', 'src/**/*.d.ts', '!src/components/slides/swiper-widget.*']).then(() => {
13+
del(['src/**/*.js', 'src/**/*.d.ts']).then(() => {
1414
done();
1515
}).catch(err => {
1616
done(err);

scripts/gulp/tasks/demos.dev.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,8 @@ task('demos.build', function () {
8888
* Creates SystemJS bundle from Ionic source files.
8989
*/
9090
task('demos.bundle', function () {
91-
var tsResult = tsCompile(getTscOptions('es6'), 'system')
92-
.pipe(babel(babelOptions));
93-
94-
var swiper = src('src/components/slides/swiper-widget.system.js');
95-
96-
return merge([tsResult, swiper])
91+
return tsCompile(getTscOptions('es6'), 'system')
92+
.pipe(babel(babelOptions))
9793
.pipe(remember('system'))
9894
.pipe(concat('ionic.system.js'))
9995
.pipe(dest(`${DIST_NAME}/bundles`))

scripts/gulp/tasks/e2e.dev.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,8 @@ task('e2e.build', function () {
127127
* Creates SystemJS bundle from Ionic source files.
128128
*/
129129
task('e2e.bundle', function () {
130-
var tsResult = tsCompile(getTscOptions('es6'), 'system')
131-
.pipe(babel(babelOptions));
132-
133-
var swiper = src('src/components/slides/swiper-widget.system.js');
134-
135-
return merge([tsResult, swiper])
130+
return tsCompile(getTscOptions('es6'), 'system')
131+
.pipe(babel(babelOptions))
136132
.pipe(remember('system'))
137133
.pipe(concat('ionic.system.js'))
138134
.pipe(dest(`${DIST_NAME}/bundles`))

scripts/gulp/util.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UMD_MODULE, ES_2015, NODE_MODULES_ROOT, PROJECT_ROOT, SRC_ROOT, SRC_COMPONENTS_ROOT } from './constants';
1+
import { NODE_MODULES_ROOT, PROJECT_ROOT, SRC_ROOT } from './constants';
22
import { src, dest } from 'gulp';
33
import { join } from 'path';
44
import * as fs from 'fs';
@@ -138,17 +138,6 @@ export function copyFile(srcPath: string, destPath: string) {
138138
fs.writeFileSync(destPath, sourceData);
139139
}
140140

141-
export function copySwiperToPath(distPath: string, moduleType: string) {
142-
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.d.ts`, `${distPath}/swiper-widget.d.ts`);
143-
if (!moduleType || moduleType === UMD_MODULE) {
144-
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.js`, `${distPath}/swiper-widget.js`);
145-
} else if (moduleType === ES_2015) {
146-
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.es2015.js`, `${distPath}/swiper-widget.js`);
147-
} else {
148-
copyFile(`${SRC_COMPONENTS_ROOT}/slides/swiper-widget.system.js`, `${distPath}/swiper-widget.system.js`);
149-
}
150-
}
151-
152141
export function runNgc(pathToConfigFile: string, done: Function) {
153142
let exec = require('child_process').exec;
154143
var shellCommand = `node --max_old_space_size=8096 ${PROJECT_ROOT}/node_modules/.bin/ngc -p ${pathToConfigFile}`;

scripts/karma/karma.config.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export function config(config) {
1212
require('karma-jasmine'),
1313
require('karma-coverage'),
1414
require('karma-sourcemap-loader'),
15-
require('karma-chrome-launcher')
15+
require('karma-chrome-launcher'),
16+
require('karma-spec-reporter')
1617
],
1718
files: [
1819
{pattern: 'dist/vendor/core-js/client/core.js', included: true, watched: false},
@@ -37,16 +38,23 @@ export function config(config) {
3738
customLaunchers: customLaunchers,
3839

3940
exclude: [
40-
'dist/e2e/**/*',
41-
'dist/ionic-angular/components/slides/swiper-widget*'
41+
'dist/e2e/**/*'
4242
],
4343
// Source files that you wanna generate coverage for.
4444
// Do not include tests or libraries (these files will be instrumented by Istanbul)
4545
preprocessors: {
4646
'dist/ionic-angular/umd/**/!(*spec).js': ['coverage'],
4747
'dist/ionic-angular/**/*.js': ['sourcemap']
4848
},
49-
reporters: ['dots', 'coverage'],
49+
reporters: ['dots', 'coverage', 'spec'],
50+
specReporter: {
51+
maxLogLines: 5, // limit number of lines logged per test
52+
suppressErrorSummary: true, // do not print error summary
53+
suppressFailed: false, // do not print information about failed tests
54+
suppressPassed: false, // do not print information about passed tests
55+
suppressSkipped: true, // do not print information about skipped tests
56+
showSpecTiming: false // print the time elapsed for each spec
57+
},
5058
port: 9876,
5159
colors: true,
5260
logLevel: config.LOG_INFO,

scripts/polyfill/polyfill.dom.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,33 @@
2727
};
2828
}
2929

30+
31+
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
32+
// MIT license
33+
var win = window;
34+
if (!win.requestAnimationFrame) {
35+
win.requestAnimationFrame = win.webkitRequestAnimationFrame;
36+
win.cancelAnimationFrame = win.webkitCancelAnimationFrame || win.webkitCancelRequestAnimationFrame;
37+
38+
if (!win.requestAnimationFrame) {
39+
win.requestAnimationFrame = function(callback, element) {
40+
var currTime = new Date().getTime();
41+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
42+
43+
var id = win.setTimeout(function() {
44+
callback(currTime + timeToCall);
45+
}, timeToCall);
46+
47+
lastTime = currTime + timeToCall;
48+
return id;
49+
};
50+
}
51+
52+
if (!win.cancelAnimationFrame) {
53+
win.cancelAnimationFrame = function(id) {
54+
clearTimeout(id);
55+
};
56+
}
57+
}
58+
3059
})();

0 commit comments

Comments
 (0)