Skip to content

Commit

Permalink
Added more logging
Browse files Browse the repository at this point in the history
Signed-off-by: Jaid <jaid.jsx@gmail.com>
  • Loading branch information
Jaid committed Jun 19, 2021
1 parent a357399 commit 2717234
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,37 @@ import debug from "lib/debug"
*/
export default class InjectBrowserSyncPlugin {

/**
* @constructor
* @param {Options} [options] Plugin options
*/
constructor(options) {
this.options = {
content: "<div id=\"root\"></div>",
position: "start",
...options,
}
}
// /**
// * @constructor
// * @param {Options} [options] Plugin options
// */
// constructor(options) {
// this.options = {
// content: "<div id=\"root\"></div>",
// position: "start",
// ...options,
// }
// }

/**
* @param {import("webpack").Compiler} compiler
*/
apply(compiler) {
debug("Options: %o", this.options)
compiler.hooks.compilation.tap(process.env.REPLACE_PKG_NAME, compilation => {
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(process.env.REPLACE_PKG_NAME, (data, cb) => {
debug("tap: compilation")
HtmlWebpackPlugin.getHooks(compilation).beforeEmit.tapAsync(process.env.REPLACE_PKG_NAME, (data, callback) => {
debug("tapAsync: html-webpack-plugin beforeEmit")
debug("Before: %s", data.html)
if (this.options.position === "end") {
data.html = insertStringBefore(data.html, "</body>", this.options.content)
} else {
data.html = insertStringAfter(data.html, "<body>", this.options.content)
}
debug(" After: %s", data.html)
cb(null, data)
callback(null, data)
})
})
}

}

0 comments on commit 2717234

Please sign in to comment.