Change headReg and bodyReg to allow spaces (#709)

* change headReg and bodyReg to allow spaces

* change regex to only allow space before closing tag
This commit is contained in:
Anchen 2017-06-29 17:08:52 +10:00 committed by Jan Nicklas
parent 2cc10df68f
commit bd043db35d
3 changed files with 37 additions and 2 deletions

View File

@ -521,8 +521,8 @@ HtmlWebpackPlugin.prototype.generateAssetTags = function (assets) {
*/
HtmlWebpackPlugin.prototype.injectAssetsIntoHtml = function (html, assets, assetTags) {
var htmlRegExp = /(<html[^>]*>)/i;
var headRegExp = /(<\/head>)/i;
var bodyRegExp = /(<\/body>)/i;
var headRegExp = /(<\/head\s*>)/i;
var bodyRegExp = /(<\/body\s*>)/i;
var body = assetTags.body.map(this.createHtmlTag);
var head = assetTags.head.map(this.createHtmlTag);

View File

@ -1513,4 +1513,32 @@ describe('HtmlWebpackPlugin', function () {
},
[/^<script type="text\/javascript" src="app_bundle\.js"><\/script>$/], null, done);
});
it('allows you to inject the assets into the body of the given spaced closing tag template', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
inject: 'body',
template: path.join(__dirname, 'fixtures/spaced_plain.html')
})]
}, [/<body>[\s]*<script type="text\/javascript" src="index_bundle.js"><\/script>[\s]*<\/body\s>/], null, done);
});
it('allows you to inject the assets into the head of the given spaced closing tag template', function (done) {
testHtmlPlugin({
entry: path.join(__dirname, 'fixtures/index.js'),
output: {
path: OUTPUT_DIR,
filename: 'index_bundle.js'
},
plugins: [new HtmlWebpackPlugin({
inject: 'head',
template: path.join(__dirname, 'fixtures/spaced_plain.html')
})]
}, [/<head>[\s]*<script type="text\/javascript" src="index_bundle.js"><\/script>[\s]*<\/head\s>/], null, done);
});
});

7
spec/fixtures/spaced_plain.html vendored Normal file
View File

@ -0,0 +1,7 @@
<!doctype html>
<html lang="en" manifest="foo.appcache">
<head>
</head >
<body>
</body >
</html>