Skip to content

Commit

Permalink
feat: return name and path of element
Browse files Browse the repository at this point in the history
  • Loading branch information
vagusX committed Mar 27, 2017
1 parent 985b2be commit f7fbfc2
Show file tree
Hide file tree
Showing 3 changed files with 2,793 additions and 9 deletions.
18 changes: 10 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import loaderUtils from 'loader-utils'

module.exports = () => ''
const domModuleRegex = /<dom-module.*?id=["'](.*?)["'].*?>/

module.exports.pitch = function (remainingRequest) {
module.exports = function (content) {
this.cacheable && this.cacheable()

const url = loaderUtils.interpolateName(this, '[path][name].[ext]', {
context: this.options.context
})

return `
var link = document.createElement('link')
link.rel = 'import'
link.href = '${url}'
document.head.appendChild(link)
`
const meta = { url }
const result = content.match(domModuleRegex)

if (Array.isArray(result) && result[1]) {
meta.name = result[1]
}

return `module.exports = ${JSON.stringify(meta)}`
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"rollup-plugin-node-globals": "^1.1.0",
"semantic-release": "^6.3.2",
"standard": "^9.0.2",
"tape": "^4.6.3",
"validate-commit-message": "^3.0.1"
},
"dependencies": {
Expand Down
Loading

0 comments on commit f7fbfc2

Please sign in to comment.