Skip to content

Commit 1ae7af3

Browse files
committed
fix lazy loading with rollup
1 parent 6432bd4 commit 1ae7af3

File tree

15 files changed

+106
-43
lines changed

15 files changed

+106
-43
lines changed

atmosphere-packages/angular-compilers/.versions

Lines changed: 4 additions & 4 deletions

atmosphere-packages/angular-compilers/package.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'angular-compilers',
3-
version: '0.3.1',
3+
version: '0.3.1_1',
44
summary: 'Rollup, AOT, SCSS, HTML and TypeScript compilers for Angular Meteor',
55
git: 'https://github.com/Urigo/angular-meteor/tree/master/atmosphere-packages/angular-compilers',
66
documentation: 'README.md'
@@ -14,9 +14,9 @@ Package.registerBuildPlugin({
1414
use: [
1515
// Uses an external packages to get the actual compilers
1616
17-
18-
19-
17+
18+
19+
2020
]
2121
});
2222

atmosphere-packages/angular-html-compiler/.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
33
44

atmosphere-packages/angular-html-compiler/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'angular-html-compiler',
3-
version: '0.3.1',
3+
version: '0.3.1_1',
44
summary: 'Angular Html Compiler Package',
55
git: 'https://github.com/Urigo/angular-meteor/tree/master/atmosphere-packages/angular-html-compiler',
66
documentation: null

atmosphere-packages/angular-scss-compiler/.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
33
44
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const path = Npm.require('path');
2+
3+
export const basePath = process.cwd();
4+
5+
export function getMeteorPath(filePath) {
6+
if (filePath.startsWith(basePath)) {
7+
filePath = filePath.slice(basePath.length);
8+
}
9+
return getNoRooted(filePath);
10+
}
11+
12+
const ROOTED = /^(\/|\\)/;
13+
14+
export function isRooted(filePath) {
15+
return ROOTED.test(filePath);
16+
}
17+
18+
export function getNoRooted(filePath) {
19+
if (isRooted(filePath)) {
20+
return filePath.slice(1);
21+
}
22+
return filePath;
23+
}
24+
25+
export function getFullPath(filePath) {
26+
filePath = getMeteorPath(filePath);
27+
return path.join(basePath, filePath);
28+
}
29+
30+
export function removeTsExtension(filePath) {
31+
if (filePath.endsWith('.ts')) {
32+
return filePath.slice(0, -3);
33+
}
34+
return filePath;
35+
}

atmosphere-packages/angular-scss-compiler/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ const sass = Npm.require('node-sass');
22

33
const path = Npm.require('path');
44

5-
const basePath = process.cwd();
5+
import {
6+
basePath,
7+
ROOTED,
8+
getMeteorPath,
9+
isRooted,
10+
getNoRooted
11+
} from './file-utils';
612

713
const WEB_ARCH_REGEX = /^web/;
814

@@ -18,7 +24,7 @@ export class AngularScssCompiler{
1824
return CACHE.get(filePath);
1925
}
2026
static compileFile(filePath, data){
21-
const fullPath = filePath.includes(basePath) ? filePath : path.join(basePath, filePath);
27+
const fullPath = isRooted(filePath) ? filePath : path.join(basePath, filePath);
2228
return sass.renderSync({
2329
file: fullPath,
2430
includePaths: [basePath + '/node_modules'],

atmosphere-packages/angular-scss-compiler/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'angular-scss-compiler',
3-
version: '0.3.1',
3+
version: '0.3.1_1',
44
summary: 'Angular Scss Compiler Package',
55
git: 'https://github.com/Urigo/angular-meteor/tree/master/atmosphere-packages/angular-scss-compiler',
66
documentation: null

atmosphere-packages/angular-typescript-compiler/.versions

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
2-
3-
1+
2+
3+
44
55
66

atmosphere-packages/angular-typescript-compiler/index.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ const ngcOptions = {
6565
traceResolution: false,
6666
};
6767

68-
6968
export class AngularTsCompiler {
7069
constructor({aot, rollup}){
7170
this.isAot = aot;
@@ -76,7 +75,7 @@ export class AngularTsCompiler {
7675
}
7776

7877
}
79-
addFakeDynamicLoader(source, basePath) {
78+
generateFakeDynamicLoader(source, basePath) {
8079

8180
let fakeLoaderCode = '';
8281

@@ -88,14 +87,13 @@ export class AngularTsCompiler {
8887
(this.isAot ? '.ngfactory' : '') +
8988
replaced[0];
9089

91-
fakeLoaderCode += `function fakeLoader(){module.dynamicImport(${fixedUrl})}`;
90+
additionFakeLoaderCode += `
91+
if(false){module.dynamicImport(${fixedUrl})}
92+
`;
9293
return `loadChildren: ${replaced}`;
93-
})
94-
95-
if (fakeLoaderCode)
96-
newSource = fakeLoaderCode + '\n' + newSource;
94+
});
9795

98-
return newSource;
96+
return {additionFakeLoaderCode, newSource};
9997

10098
}
10199
replaceStringsWithFullUrls(basePath, urls, firstSlash) {
@@ -209,6 +207,7 @@ export class AngularTsCompiler {
209207
let mainCodePath;
210208
let mainCode;
211209
const codeMap = new Map();
210+
let fakeLoaderCode = '';
212211
console.time(`[${prefix}]: TypeScript Files Compilation`);
213212
for (const filePath of allPaths) {
214213
if (!filePath.endsWith('.d.ts')) {
@@ -237,24 +236,34 @@ export class AngularTsCompiler {
237236
if (!this.isAot) {
238237
code = this.fixResourceUrls(code, basePath)
239238
}
240-
code = this.addFakeDynamicLoader(code, basePath);
239+
let {newSource, additionFakeLoaderCode} = this.generateFakeDynamicLoader(code, basePath);
240+
code = newSource;
241+
fakeLoaderCode += additionFakeLoaderCode;
241242
code = code.split('require("node_modules/').join('require("');
242243
const inputPath = inputFile.getPathInPackage();
243244
const outputPath = this.removeTsExtension(filePath);
244245
if (this.isRollup) {
245246
codeMap.set(outputPath, code);
246-
} else {
247-
const toBeAdded = {
248-
sourcePath: inputPath,
249-
path: outputPath + '.js',
250-
data: code,
251-
hash: result.hash,
252-
sourceMap: result.sourceMap
253-
};
254-
inputFile.addJavaScript(toBeAdded);
255247
}
248+
const toBeAdded = {
249+
sourcePath: inputPath,
250+
path: outputPath + '.js',
251+
data: code,
252+
hash: result.hash,
253+
sourceMap: result.sourceMap
254+
};
255+
inputFile.addJavaScript(toBeAdded);
256256
}
257257
}
258+
const inputFile = inputFiles.find(file => {
259+
const filePath = file.getPathInPackage();
260+
return filePath.startsWith(prefix) &&
261+
filePath.indexOf('imports') === -1;
262+
});
263+
inputFile.addJavaScript({
264+
path: 'fakeLoader.js',
265+
data: fakeLoaderCode
266+
});
258267
console.timeEnd(`[${prefix}]: TypeScript Files Compilation`);
259268
if (this.isRollup && !mainCodePath.includes('node_modules')) {
260269
console.time(`[${prefix}]: Rollup`);

0 commit comments

Comments
 (0)