Last active
September 27, 2017 17:41
-
-
Save mildmojo/62f86a73a61f8f4d6b04e8a2ee9dd7ba to your computer and use it in GitHub Desktop.
Webpack loader that inserts original source filenames as HTML comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
html-annotate-filenames | |
Webpack loader that surrounds generated HTML blocks with comments noting the | |
original source filename for the block. | |
To use, modify your webpack config with a `resolveLoader` that can find this | |
file and a rule for this loader. Example: | |
{ | |
entry: "...", | |
resolveLoader: { | |
modules: ["node_modules", path.resolve(__dirname, "loaders")] | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.html$/, | |
enforce: "pre", | |
use: { | |
loader: "html-annotate-filenames" | |
} | |
} | |
] | |
} | |
} | |
Tested with webpack 2.7.0. | |
*/ | |
'use strict'; | |
const loaderUtils = require('loader-utils'); | |
module.exports = function(content) { | |
const filename = loaderUtils.interpolateName(this, '[name].[ext]', {content}); | |
return `<!-- begin ${filename} -->\n${content}\n<!-- end ${filename} -->`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before:
After: