Skip to content

Commit

Permalink
improve: Added debug log
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 fd42ec0 commit a357399
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import HtmlWebpackPlugin from "html-webpack-plugin"
import insertStringAfter from "insert-string-after"
import insertStringBefore from "insert-string-before"

import debug from "lib/debug"

/**
* @typedef {Object} Options
* @prop {string} content
Expand Down Expand Up @@ -31,13 +33,16 @@ export default class InjectBrowserSyncPlugin {
* @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("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)
})
})
Expand Down
3 changes: 3 additions & 0 deletions src/lib/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import debug from "debug"

export default debug(process.env.REPLACE_PKG_NAME)

0 comments on commit a357399

Please sign in to comment.