How to use html-loader - 1 common examples

To help you get started, we’ve selected a few html-loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github niieani / webpack-dependency-suite / loaders / html-require-loader.ts View on Github external
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(`*`))

html-loader

Html loader module for webpack

MIT
Latest version published 4 months ago

Package Health Score

89 / 100
Full package analysis

Popular html-loader functions