string-replace is a package used to find a string match in a file and replace it
string-replace is available as an NPM package:
npm i @mlnop/string-replace --save-dev
const {stringReplaceOpenAndWrite, stringReplace} = require("@mlnop/string-replace");
const {resolve} = require("path");
// single file usage
stringReplaceOpenAndWrite(resolve(__dirname, "README.md"), [
{
from: /\bstring-replace/g,
to: "ayaya",
},
]);
// single or multiple file usage
stringReplace([
{
filePath: [resolve(__dirname, "README.md")],
replace: [
{
from: /\bstring-replace/g,
to: "ayaya",
},
{
from: /\bUsage example/g,
to: "hello there",
},
],
},
{
filePath: resolve(__dirname, "README.md"),
replace: [
{
from: /\bstring-replace/g,
to: "ayaya",
},
{
from: /\bUsage example/g,
to: "hello there",
},
],
},
]);
for the vite compatibilty, you can pass a hook as second parameter in the function ("closeBundle" is the default value)
const {viteStringReplace} = require("@mlnop/string-replace");
const {resolve} = require("path");
// vite plugin single or multiple file usage
viteStringReplace(
[
{
filePath: [resolve(__dirname, "README.md")],
replace: [
{
from: /\bstring-replace/g,
to: "ayaya",
},
{
from: /\bUsage example/g,
to: "hello there",
},
],
},
{
filePath: resolve(__dirname, "README.md"),
replace: [
{
from: /\bstring-replace/g,
to: "ayaya",
},
{
from: /\bUsage example/g,
to: "hello there",
},
],
},
],
"closeBundle"
);
- Added vite compatibility
- Published to NPM.
- First commit.
- Published to NPM.