Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit f1ba503

Browse files
committed
Reexport PlatformSuffixPlugin in index, functional style css2json-loader
1 parent ec3f9cb commit f1ba503

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

Diff for: css2json-loader.js

+15-27
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
console.log("Here: " + __dirname);
2-
31
const parse = require("tns-core-modules/css").parse;
4-
52
const nl = "\n";
63

7-
function escape(string) {
8-
return JSON.stringify(string);
4+
module.exports = function(content) {
5+
const ast = parse(content);
6+
const dependencies = getImportsFrom(ast)
7+
.map(mapURI)
8+
.reduce((dependencies, {uri, requireURI}) =>
9+
dependencies + `global.registerModule(${uri}, () => require(${requireURI}));${nl}`, "");
10+
11+
const str = JSON.stringify(ast, (k, v) => k === "position" ? undefined : v);
12+
return `${dependencies}module.exports = ${str};`;
913
}
1014

11-
function importsFrom(ast) {
15+
function getImportsFrom(ast) {
1216
if (!ast || ast.type !== "stylesheet" || !ast.stylesheet) {
1317
return [];
1418
}
@@ -17,25 +21,9 @@ function importsFrom(ast) {
1721
.map(importRule => importRule.import.replace(/[\'\"]/gm, ""));
1822
}
1923

20-
// Identity loader
21-
module.exports = function(content) {
22-
this.cacheable && this.cacheable();
23-
this.value = content;
24-
const ast = parse(content);
25-
26-
let dependencies = "";
27-
28-
importsFrom(ast).forEach(uri => {
29-
if (uri[0] === "~" && uri[1] !== "/") {
30-
// Require form node modules from `~nativescript-theme` like imports.
31-
dependencies += `global.registerModule(${escape(uri)}, () => require(${escape(uri.substr(1))}));${nl}`;
32-
} else {
33-
dependencies += `global.registerModule(${escape(uri)}, () => require(${escape(uri)});${nl}`;
34-
}
35-
});
36-
37-
const str = JSON.stringify(ast, (k, v) => k === "position" ? undefined : v);
38-
return `${dependencies}module.exports = ${str};`;
24+
function mapURI(uri) {
25+
return {
26+
uri: JSON.stringify(uri),
27+
requireURI: JSON.stringify(uri[0] === "~" && uri[1] !== "/" ? uri.substr(1) : uri)
28+
};
3929
}
40-
module.exports.seperable = true;
41-

Diff for: PlatformSuffixPlugin.js renamed to plugins/PlatformSuffixPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function PlatformSuffixPlugin(platform, platforms) {
44
this.platform = platform;
55
this.platforms = platforms || ["ios", "android"];
66
}
7-
module.exports = PlatformSuffixPlugin;
7+
exports.PlatformSuffixPlugin = PlatformSuffixPlugin;
88

99
PlatformSuffixPlugin.prototype.apply = function(resolver) {
1010
var platform = this.platform;

Diff for: plugins/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = Object.assign({},
22
require("./GenerateBundleStarterPlugin"),
33
require("./NativeScriptJsonpPlugin"),
4-
require("./NativeScriptSnapshotPlugin")
4+
require("./NativeScriptSnapshotPlugin"),
5+
require("./PlatformSuffixPlugin")
56
);

0 commit comments

Comments
 (0)