Skip to content

Commit

Permalink
fix loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Dec 21, 2017
1 parent 18a794f commit 9ec73e0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
9 changes: 5 additions & 4 deletions packages/veui-loader/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function patchComponent(content, component, options, resolve) {

return Object.keys(parts).reduce(function (content, type) {
return parts[type].reduce(function (content, peerPath) {
return patchType(content, type, (0, _utils.normalize)(peerPath));
return patchType(content, type, peerPath);
}, content);
}, content);
}
Expand All @@ -109,19 +109,20 @@ function getExtname(file) {
var RE_SCRIPT = /<script(?:\s+[^>]*)?>/i;

function patchType(content, type, peerPath) {
var normalizedPath = (0, _utils.normalize)(peerPath).replace(/\\/g, '\\\\');
switch (type) {
case 'script':
content = content.replace(RE_SCRIPT, function (match) {
return match + '\nimport \'' + peerPath + '\'\n';
return match + '\nimport \'' + normalizedPath + '\'\n';
});
break;
case 'style':
var langStr = '';
var ext = getExtname(peerPath);
var ext = getExtname(normalizedPath);
if (ext !== 'css') {
langStr = 'lang="' + ext + '" ';
}
content += '\n<style ' + langStr + 'src="' + peerPath + '"></style>\n';
content += '\n<style ' + langStr + 'src="' + normalizedPath + '"></style>\n';
break;
default:
break;
Expand Down
69 changes: 60 additions & 9 deletions packages/veui-loader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/veui-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const RE_SCRIPT = /<script(?:\s+[^>]*)?>/i
* @returns {string} The patched content
*/
function patchType (content, type, peerPath) {
let normalizedPath = normalize(peerPath)
let normalizedPath = normalize(peerPath).replace(/\\/g, '\\\\')
switch (type) {
case 'script':
content = content.replace(RE_SCRIPT, match => {
Expand Down

0 comments on commit 9ec73e0

Please sign in to comment.