Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function HtmlRequireLoader (this: Webpack.Core.LoaderContext, pureHtml: string, sourceMap?: SourceMap.RawSourceMap) {
if (this.cacheable) {
this.cacheable()
}
const query = Object.assign({}, htmlRequireDefaults, loaderUtils.parseQuery(this.query)) as HtmlRequireOptions & {selectorsAndAttributes: Array}
const source = htmlLoader.bind(this)(pureHtml, sourceMap) as string
try {
const resources = getTemplateResourcesData(pureHtml, query.selectorsAndAttributes, query.globReplaceRegex)
if (!resources.length) {
return source
}
return (async () => {
this.async()
let resourceData = await addBundleLoader(resources)
log(`Adding resources to ${this.resourcePath}: ${resourceData.map(r => r.literal).join(', ')}`)
if (query.enableGlobbing) {
resourceData = await expandAllRequiresForGlob(resourceData, this)
} else {
resourceData = resourceData.filter(r => !r.literal.includes(`*`))