Skip to content

Commit

Permalink
feat: basic new version
Browse files Browse the repository at this point in the history
  • Loading branch information
vagusX committed Mar 27, 2017
1 parent 512a46b commit 24e62ec
Show file tree
Hide file tree
Showing 4 changed files with 860 additions and 937 deletions.
38 changes: 37 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var loaderUtils = require('loader-utils')
var fs = require('fs')
var path = require('path')
var Vulcanize = require('vulcanize')

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

var emitFile = false

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

Expand All @@ -14,7 +19,38 @@ module.exports = function (content) {

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

if (!emitFile) return 'module.exports = ' + (JSON.stringify(meta))

meta.url = result[1] + '.html'

var _this = this
var callback = this.async()

bundler(url, function(inlinedHtml) {
_this.emitFile(result[1] + '.html', inlinedHtml)
callback(null, 'module.exports = ' + (JSON.stringify(meta)))
})
} else {
return 'module.exports = ' + (JSON.stringify(meta))
}
}

return ('module.exports = ' + (JSON.stringify(meta)))
// ===== vulcanize =====
function bundler (target, callback) {
new Vulcanize({
inlineScripts: true,
inlineCss: true,
stripComments: true
}).process(target, function (err, inlinedHtml) {
onError(err)
callback(inlinedHtml)
})
}

function onError (err) {
if (err) {
console.error(err + '\n' + err.stack)
throw err
}
}
36 changes: 36 additions & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// MyPlugin.js

function MyPlugin (options) {
// Configure your plugin with options...
}

MyPlugin.prototype.apply = function (compiler) {

console.log(compiler.resolvers.loader)

compiler.plugin('compile', function (params) {
console.log('The compiler is starting to compile...')
})

compiler.plugin('compilation', function (compilation) {
console.log('The compiler is starting a new compilation...')

compilation.plugin('optimize', function () {
console.log('The compilation is starting to optimize files...')
})

compilation.plugin('optimize-tree', function(chunks, modules) {
console.log(chunks)
});
})

compiler.plugin('emit', function (compilation, callback) {
const webpackStatsJson = compilation.getStats().toJson()
// console.log(webpackStatsJson)
const outputPath = compilation.compiler.outputPath;
console.log('The compilation is going to emit files...')
callback()
})
}

module.exports = MyPlugin
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
"homepage": "https://github.com/vagusX/html-imports-loader#readme",
"devDependencies": {
"ghooks": "^2.0.0",
"polymer-build": "^0.9.1",
"polymer-bundler": "^2.0.0-pre.6",
"semantic-release": "^6.3.2",
"validate-commit-message": "^3.0.1"
},
"dependencies": {
"loader-utils": "^1.1.0"
"loader-utils": "^1.1.0",
"vulcanize": "^1.15.4"
}
}
Loading

0 comments on commit 24e62ec

Please sign in to comment.