Skip to content

Commit

Permalink
Merge pull request #17 from SCullman/patch-1
Browse files Browse the repository at this point in the history
Support RegEx again
  • Loading branch information
iminif committed Sep 21, 2019
2 parents 27d1200 + f624b24 commit 65afdbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ module.exports = {
{
pattern: '@@title',
replacement: 'html replace webpack plugin'
},
{
pattern: /<p>(.+?)<\/p>/g, // /g => replace all
replacement: '<div>$1</div>'
},
{
pattern: /(<!--\s*|@@)(css|js|img):([\w-\/]+)(\s*-->)?/g,
Expand Down Expand Up @@ -90,6 +94,7 @@ module.exports = {
</head>
<body>
<div>foo</div>
<p>I wanna be in a div</p>
<!-- js:bootstrap -->
</body>
</html>
Expand All @@ -106,6 +111,7 @@ module.exports = {
</head>
<body>
<div>`foo` has been replaced with `bar`</div>
<div>I wanna be in a div</div>
<script type="text/javascript" src="//cdn/bootstrap/bootstrap.min.js"></script>
</body>
</html>
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ function HtmlReplaceWebpackPlugin(options) {
htmlPluginData.html = htmlPluginData.html.replace(matches[0], replacement)
}
} else {
// htmlPluginData.html.replace(option.pattern, option.replacement)
htmlPluginData.html = htmlPluginData.html.split(option.pattern).join(option.replacement)
if (option.pattern instanceof RegExp)
htmlPluginData.html = htmlPluginData.html.replace(option.pattern, option.replacement)
else htmlPluginData.html = htmlPluginData.html.split(option.pattern).join(option.replacement)
}
})

Expand Down

0 comments on commit 65afdbf

Please sign in to comment.