lib/polymerize.js
function polymerize(src, filepath) {

  // Parse web-component source (extract dependency, optimize source, etc.)
  var result = parseSource(src, filepath);

  // Generate commonjs module source:
  var src = [];

  // Require imported web-components
  result.imports.forEach(function(imp) {
    src.push('require("'+imp+'");')
  });

  // Once DOMContentLoaded
  src.push('document.addEventListener("DOMContentLoaded",function() {');

  // Inject html source
  if(result.head) {
    src.push('var head = document.getElementsByTagName("head")[0];')
    src.push('head.insertAdjacentHTML("beforeend",'+JSON.stringify(result.head)+');')
  }

  if(result.body) {
    src.push('var body = document.getElementsByTagName("body")[0];')
    src.push('var root = body.appendChild(document.createElement("div"));')
    src.push('root.setAttribute("hidden","");')
    src.push('root.innerHTML=' + JSON.stringify(result.body)+ ';')
  }

  // Require scripts
  result.scripts.forEach(function(script) {
    src.push('require("'+script+'");')
  })

  // Append inline sources
  result.inline.forEach(function(inline) {
    src.push(';(function() {\n'+inline+'\n})();')
  })

  // End DOMContentLoaded
  src.push('\n})')

  return src.join('\n')
}
function polymerize(src, filepath) {

  // Parse web-component source (extract dependency, optimize source, etc.)
  var result = parseSource(src, filepath);

  // Generate commonjs module source:
  var src = [];

  // Require imported web-components
  result.imports.forEach(function(imp) {
    src.push('require("'+imp+'");')
  });

  // Once DOMContentLoaded
  src.push('document.addEventListener("DOMContentLoaded",function() {');

  // Inject html source
  if(result.head) {
    src.push('var head = document.getElementsByTagName("head")[0];')
    src.push('head.insertAdjacentHTML("beforeend",'+JSON.stringify(result.head)+');')
  }

  if(result.body) {
    src.push('var body = document.getElementsByTagName("body")[0];')
    src.push('var root = body.appendChild(document.createElement("div"));')
    src.push('root.setAttribute("hidden","");')
    src.push('root.innerHTML=' + JSON.stringify(result.body)+ ';')
  }

  // Require scripts
  result.scripts.forEach(function(script) {
    src.push('require("'+script+'");')
  })

  // Append inline sources
  result.inline.forEach(function(inline) {
    src.push(';(function() {\n'+inline+'\n})();')
  })

  // End DOMContentLoaded
  src.push('\n})')

  return src.join('\n')
}
function polymerize ( src , filepath ) { // Parse web-component source (extract dependency, optimize source, etc.) var result = parseSource ( src , filepath ) ; // Generate commonjs module source: var src = [ ] ; // Require imported web-components result . imports . forEach ( function ( imp ) { src . push ( 'require("' + imp + '");' ) } ) ; // Once DOMContentLoaded src . push ( 'document.addEventListener("DOMContentLoaded",function() {' ) ; // Inject html source if ( result . head ) { src . push ( 'var head = document.getElementsByTagName("head")[0];' ) src . push ( 'head.insertAdjacentHTML("beforeend",' + JSON . stringify ( result . head ) + ');' ) } if ( result . body ) { src . push ( 'var body = document.getElementsByTagName("body")[0];' ) src . push ( 'var root = body.appendChild(document.createElement("div"));' ) src . push ( 'root.setAttribute("hidden","");' ) src . push ( 'root.innerHTML=' + JSON . stringify ( result . body ) + ';' ) } // Require scripts result . scripts . forEach ( function ( script ) { src . push ( 'require("' + script + '");' ) } ) // Append inline sources result . inline . forEach ( function ( inline ) { src . push ( ';(function() {\n' + inline + '\n})();' ) } ) // End DOMContentLoaded src . push ( '\n})' ) return src . join ( '\n' ) }
Polymer vulcanization for browserify

@param  {String} src
Web component html source

@param  {String} filepath
Source filepath

@return {String}
CommonJS source with external import module and stylesheet
as `require()` calls
Polymer vulcanization for browserify