Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit eaf5386

Browse files
authored
chore: add moduleId removal loader (#410)
1 parent 6e39693 commit eaf5386

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ debug.log
66
src/**/*.js
77
!src/systemjs.config.extras.js
88
!src/systemjs.config.js
9+
!src/systemjs-angular-loader.js
910
*.js.map
1011
e2e/**/*.js
1112
e2e/**/*.js.map

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Upgraders: for a fresh start, consider running these commands
33
* `git clean -xdf`
44
* `npm install`
55

6+
<a name="0.3.0"></a>
7+
# 0.3.0 (2017-03-22)
8+
* Remove moduleId with a systemjs loader.
9+
610
<a name="0.2.22"></a>
711
# 0.2.22 (2017-01-05)
812
* Add `non-essential-files.txt` and instructions to use it to README

src/systemjs-angular-loader.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*)/gm;
2+
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
3+
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;
4+
5+
module.exports.translate = function(load){
6+
7+
var url = new URL(load.address);
8+
9+
var basePathParts = url.pathname.split('/');
10+
11+
basePathParts.pop();
12+
var basePath = basePathParts.join('/');
13+
14+
var baseHref = new URL(this.baseURL).pathname;
15+
16+
basePath = basePath.replace(baseHref, '');
17+
18+
load.source = load.source
19+
.replace(templateUrlRegex, function(match, quote, url){
20+
let resolvedUrl = url;
21+
22+
if (url.startsWith('.')) {
23+
resolvedUrl = basePath + url.substr(1);
24+
}
25+
26+
return `templateUrl: '${resolvedUrl}'`;
27+
})
28+
.replace(stylesRegex, function(match, relativeUrls) {
29+
var urls = [];
30+
31+
while ((match = stringRegex.exec(relativeUrls)) !== null) {
32+
if (match[2].startsWith('.')) {
33+
urls.push(`'${basePath}${match[2].substr(1)}'`);
34+
} else {
35+
urls.push(`'${match[2]}'`);
36+
}
37+
}
38+
39+
return "styleUrls: [" + urls.join(', ') + "]";
40+
});
41+
42+
return load;
43+
};

src/systemjs.config.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// map tells the System loader where to look for things
1212
map: {
1313
// our app is within the app folder
14-
app: 'app',
14+
'app': 'app',
1515

1616
// angular bundles
1717
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
@@ -30,7 +30,12 @@
3030
// packages tells the System loader how to load when no filename and/or no extension
3131
packages: {
3232
app: {
33-
defaultExtension: 'js'
33+
defaultExtension: 'js',
34+
meta: {
35+
'./*.js': {
36+
loader: 'systemjs-angular-loader.js'
37+
}
38+
}
3439
},
3540
rxjs: {
3641
defaultExtension: 'js'

0 commit comments

Comments
 (0)