text: var loaderUtils = require('loader-utils')
  var fs = require('fs')
  var path = require('path')
  var generateTemplate = require('./generateTemplate')
  var Vulcanize = require('vulcanize')
  
  var domModuleRegex = /<dom-module.*?id=["'](.*?)["'].*?>/
  
  module.exports = function (content) {
    this.cacheable && this.cacheable()
  
    var url = loaderUtils.interpolateName(this, '[path][name].[ext]', {
      context: this.options.context
    })
  
    var publicPath = this.options.output.publicPath
  
    var meta = { url: path.join(publicPath, url) }
  
    var result = content.match(domModuleRegex)
  
    var emitFile = this.query.emitFile
  
    if (Array.isArray(result) && result[1]) {
      meta.tagName = result[1]
  
      if (!emitFile) return generateTemplate(meta)
  
      meta.url = path.join(publicPath, result[1] + '.html')
  
      var callback = this.async()
      var _this = this
  
      bundler(url, function(inlinedHtml) {
        _this.emitFile(result[1] + '.html', inlinedHtml)
        callback(null, generateTemplate(meta))
      })
    } else {
      throw new Error('This html module dont have any module id')
    }
  }
  
  // ===== vulcanize =====
  function bundler (target, callback) {
    new Vulcanize({
      inlineScripts: true,
      inlineCss: true,
      stripComments: true
    }).process(target, function (err, inlinedHtml) {
      if (err) throw err
      callback(inlinedHtml)
    })
  }
  