Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit d821b3d

Browse files
committed
First commit
0 parents  commit d821b3d

File tree

9 files changed

+3564
-0
lines changed

9 files changed

+3564
-0
lines changed

.eslintrc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"extends": [ "eslint:recommended" ],
3+
"env": {
4+
"node": false,
5+
"browser": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 2017,
9+
"sourceType": "module"
10+
},
11+
"rules": {
12+
"no-console": "off",
13+
"no-unused-vars": "warn",
14+
"quotes": [
15+
"error",
16+
"single"
17+
],
18+
"semi": [
19+
2,
20+
"always"
21+
]
22+
},
23+
"globals": {
24+
"Promise": true,
25+
"System": true
26+
},
27+
"overrides": [{
28+
"files": "",
29+
"rules": {
30+
"quotes": [2, "double"]
31+
}
32+
}]
33+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
systemjs-css-extra
2+
===
3+
4+
Simple CSS loader extra for SystemJS v4 and up

build/build.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const babel = require('@babel/core');
3+
4+
// Transpile to ES5
5+
let transpiled = babel.transformFileSync('src/css.js', {
6+
configFile: false,
7+
comments: false,
8+
sourceMaps: false,
9+
presets: ['@babel/preset-env']
10+
});
11+
12+
// Transpile to ES5 and minify
13+
let transpiled_minified = babel.transformFileSync('src/css.js', {
14+
configFile: false,
15+
comments: false,
16+
sourceMaps: false,
17+
presets: ['@babel/preset-env', 'minify']
18+
});
19+
20+
fs.writeFileSync('dist/css.js', transpiled.code);
21+
fs.writeFileSync('dist/css.min.js', transpiled_minified.code);

dist/css.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
(function () {
4+
var systemPrototype = System.constructor.prototype;
5+
var originalInstantiate = systemPrototype.instantiate;
6+
7+
systemPrototype.instantiate = function () {
8+
var loader = this;
9+
var url = arguments[0];
10+
11+
if (url.slice(-4) === '.css') {
12+
return new Promise(function (resolve, reject) {
13+
if (document.querySelector('link[href="' + url + '"]') || document.querySelector('link[href="' + url.replace(location.protocol + '//' + location.hostname, '') + '"]')) {
14+
reject(Error('Style ' + url + ' has already been loaded'));
15+
}
16+
17+
var link = document.createElement('link');
18+
link.type = 'text/css';
19+
link.rel = 'stylesheet';
20+
link.href = url;
21+
document.head.appendChild(link);
22+
23+
link.onload = function () {
24+
resolve(loader.getRegister());
25+
};
26+
27+
link.onerror = function () {
28+
var href = document.querySelector('link[href="' + url + '"]');
29+
30+
if (href) {
31+
href.parentElement.removeChild(href);
32+
}
33+
34+
reject(Error('Style ' + url + ' has failed loading'));
35+
};
36+
});
37+
} else {
38+
return originalInstantiate.apply(this, arguments);
39+
}
40+
};
41+
})();

dist/css.min.js

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

0 commit comments

Comments
 (0)