Security News
New Python Packaging Proposal Aims to Solve Phantom Dependency Problem with SBOMs
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
html-replace-webpack-plugin
Advanced tools
A Webpack plugin for replace HTML contents with custom pattern string or regex.
A Webpack plugin for replace HTML contents with custom pattern string or regex.
First, install html-replace-webpack-plugin
as a development dependency:
npm install html-replace-webpack-plugin --save-dev
Then, add it to your webpack.config.js
file:
webpack.config.js
file:var webpack = require('webpack')
var HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin')
module.exports = {
// Definition for Webpack plugins
plugin: [
// Replace html contents with string or regex patterns
new HtmlReplaceWebpackPlugin([
{
pattern: 'foo',
replacement: '`foo` has been replaced with `bar`'
}, ,
{
pattern: '@@title',
replacement: 'html replace webpack plugin'
},
{
pattern: /(<!--\s*|@@)(css|js|img):([\w-\/]+)(\s*-->)?/g,
replacement: function(match, $1, type, file, $4, index, input)
{
// those formal parameters could be:
// match: <-- css:bootstrap-->
// type: css
// file: bootstrap
// Then fetch css link from some resource object
// var url = resources['css']['bootstrap']
var url = resource[type][file]
// $1==='@@' <--EQ--> $4===undefined
return $4 == undefined ? url : tpl[type].replace('%s', url)
}
}])
]
}
// file types & file links
const resource = {
js:
{
'bootstrap': '//cdn/bootstrap/bootstrap.min.js'
},
css:
{
'bootstrap': '//cdn/bootstrap/bootstrap.min.css'
},
img:
{
'the-girl': '//cdn/img/the-girl.jpg'
}
}
const tpl = {
img: '<img src="%s">',
css: '<link rel="stylesheet" type="text/css" href="%s">',
js: '<script type="text/javascript" src="%s"></script>'
}
src/index.html
file:<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@@title</title>
<!-- css:bootstrap -->
</head>
<body>
<div>foo</div>
<!-- js:bootstrap -->
</body>
</html>
dist/index.html
file:<html lang="en">
<head>
<meta charset="UTF-8">
<title>html replace webpack plugin</title>
<link rel="stylesheet" type="text/css" href="//cdn/bootstrap/bootstrap.min.css">
</head>
<body>
<div>`foo` has been replaced with `bar`</div>
<script type="text/javascript" src="//cdn/bootstrap/bootstrap.min.js"></script>
</body>
</html>
html-replace-webpack-plugin can be called with an objects array or an object.
html-replace-webpack-plugin
new HtmlReplaceWebpackPlugin([obj1[, obj2[, obj3[, ...]]]] | obj)
Type: Objects Array
| Object
Type: Object
Type: String
| RegExp
string or regex pattern for matching HTML content. See the MDN documentation for RegExp for details.
Type: String
| Function
string to which the matching string be replace with, or function which return a string for replacing. See the MDN documentation for String.replace for details.
FAQs
A Webpack plugin for replace HTML contents with custom pattern string or regex.
The npm package html-replace-webpack-plugin receives a total of 7,092 weekly downloads. As such, html-replace-webpack-plugin popularity was classified as popular.
We found that html-replace-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.
Security News
Socket CEO Feross Aboukhadijeh discusses open source security challenges, including zero-day attacks and supply chain risks, on the Cyber Security Council podcast.
Security News
Research
Socket researchers uncover how threat actors weaponize Out-of-Band Application Security Testing (OAST) techniques across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.