Skip to content

Commit 5454f6b

Browse files
committed
Initial commit
0 parents  commit 5454f6b

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/dist/
3+
npm-debug.log

index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var fs = require('fs')
2+
3+
var inlineReg = /<!-- inline-plugin[\w\W\r\n]*?-->/g
4+
var pathReg = /path="(.*?)"/
5+
6+
function wrapScript(script) {
7+
return '<script>' + script + '</script>\n'
8+
}
9+
10+
function HtmlWebpackInlinePlugin(options) {
11+
// Setup the plugin instance with options...
12+
this.options = options
13+
}
14+
15+
HtmlWebpackInlinePlugin.prototype.apply = function(compiler) {
16+
compiler.plugin('compilation', function(compilation, options) {
17+
compilation.plugin('html-webpack-plugin-before-html-processing', function(htmlPluginData, callback) {
18+
var html = htmlPluginData.html
19+
var tags = html.match(inlineReg)
20+
if (tags) {
21+
tags.forEach(function(tag) {
22+
var ret = tag.match(pathReg)
23+
if (ret && ret[1]) {
24+
var scriptContent = fs.readFileSync(ret[1], 'utf8')
25+
html = html.replace(tag, wrapScript(scriptContent))
26+
}
27+
})
28+
htmlPluginData.html = html
29+
}
30+
callback(null, htmlPluginData)
31+
});
32+
});
33+
};
34+
35+
module.exports = HtmlWebpackInlinePlugin

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "html-webpack-inline-plugin",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "MIT"
11+
}

0 commit comments

Comments
 (0)