Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c1ed570

Browse files
committedMay 16, 2018
feat: add xml loader for elements from external namespaces
1 parent dd5fe11 commit c1ed570

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed
 

‎templates/webpack.javascript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = env => {
151151
].filter(loader => !!loader)
152152
},
153153

154-
{ test: /\.(html|xml)$/, use: "raw-loader" },
154+
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"},
155155

156156
{
157157
test: /\.css$/,

‎templates/webpack.typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = env => {
151151
].filter(loader => !!loader)
152152
},
153153

154-
{ test: /\.(html|xml)$/, use: "raw-loader" },
154+
{ test: /\.(html|xml)$/, use: "nativescript-dev-webpack/xml-namespace-loader"},
155155

156156
{
157157
test: /\.css$/,

‎xml-namespace-loader.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = function(source) {
2+
this.value = source;
3+
4+
const { XmlParser } = require("tns-core-modules/xml");
5+
6+
let namespaces = [];
7+
const parser = new XmlParser((event) => {
8+
const namespace = event.namespace;
9+
if (
10+
namespace &&
11+
!namespace.startsWith("http") &&
12+
namespaces.indexOf(namespace) === -1
13+
) {
14+
namespaces.push(namespace);
15+
}
16+
}, undefined, true);
17+
parser.parse(source);
18+
19+
const registerModules = namespaces.map(n =>
20+
`global.registerModule("${n}", function() { return require("${n}"); });`);
21+
22+
const json = JSON.stringify(source)
23+
.replace(/\u2028/g, '\\u2028')
24+
.replace(/\u2029/g, '\\u2029');
25+
26+
const wrapped = `${registerModules}\nmodule.exports = ${json}`;
27+
28+
this.callback(null, wrapped);
29+
}

0 commit comments

Comments
 (0)
This repository has been archived.