Skip to content

Partial of 291 #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions src/plugins/sources-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import parse5 from 'parse5';
import {
traverse,
getFilter,
normalizeUrl,
requestify,
webpackIgnoreCommentRegexp,
} from '../utils';
Expand Down Expand Up @@ -77,9 +76,17 @@ export default (options) =>
sourceCodeLocation.attrs[name].endOffset - (isValueQuoted ? 1 : 0);
const optionsForTypeFn = {
tag: tagName,
isSelfClosing: node.selfClosing,
tagStartOffset: sourceCodeLocation.startOffset,
tagEndOffset: sourceCodeLocation.endOffset,
startTag: {
startOffset: sourceCodeLocation.startTag.startOffset,
endOffset: sourceCodeLocation.startTag.endOffset,
},
endTag: sourceCodeLocation.endTag
? {
startOffset: sourceCodeLocation.endTag.startOffset,
endOffset: sourceCodeLocation.endTag.endOffset,
}
: // eslint-disable-next-line no-undefined
undefined,
attributes,
attribute: name,
attributePrefix: attribute.prefix,
Expand Down Expand Up @@ -121,46 +128,43 @@ export default (options) =>
let offset = 0;

for (const source of sources) {
const { name, value, isValueQuoted, startOffset, endOffset } = source;

let normalizedUrl = value;
let prefix = '';

const queryParts = normalizedUrl.split('!');

if (queryParts.length > 1) {
normalizedUrl = queryParts.pop();
prefix = queryParts.join('!');
}

normalizedUrl = normalizeUrl(normalizedUrl);
const {
name,
value,
isValueQuoted,
format,
runtime,
startOffset,
endOffset,
} = source;

let request = value;

if (!urlFilter(name, value, options.resourcePath)) {
// eslint-disable-next-line no-continue
continue;
}

let hash;
const indexHash = normalizedUrl.lastIndexOf('#');
const indexHash = request.lastIndexOf('#');

if (indexHash >= 0) {
hash = normalizedUrl.substring(indexHash);
normalizedUrl = normalizedUrl.substring(0, indexHash);
hash = request.substring(indexHash);
request = request.substring(0, indexHash);
}

const request = requestify(normalizedUrl);
const newUrl = prefix ? `${prefix}!${request}` : request;
const importKey = newUrl;
let importName = imports.get(importKey);
request = requestify(options.context, request);

let importName = imports.get(request);

if (!importName) {
importName = `___HTML_LOADER_IMPORT_${imports.size}___`;
imports.set(importKey, importName);
imports.set(request, importName);

options.imports.push({ importName, source: newUrl });
options.imports.push({ format, importName, request });
}

const replacementKey = JSON.stringify({ newUrl, isValueQuoted, hash });
const replacementKey = JSON.stringify({ request, isValueQuoted, hash });
let replacementName = replacements.get(replacementKey);

if (!replacementName) {
Expand All @@ -172,6 +176,7 @@ export default (options) =>
importName,
hash,
isValueQuoted,
runtime,
});
}

Expand Down
Loading