vue replace-in-file使用替换打包后指定字符

1、安装replace-in-file,版本7.2.0,GitHub 仓库中找到 replace-in-filepackage.json查看支持的node版本

https://www.npmjs.com/package/replace-in-file/v/7.2.0?activeTab=readme

复制代码
npm install replace-in-file --save-dev

2.根目录下创建postbuild.js

javascript 复制代码
const replace = require("replace-in-file");
const options = {
  files: "pack/UI/static/js/*.js",
  from: [/xx1/g, /xx2/g],
  to: ["tt1", "tt2"],
};

try {
  const results = replace.sync(options);
  console.log("Replacement results:", results);
} catch (error) {
  console.error("Error occurred:", error);
}

3.修改package.json

javascript 复制代码
"scripts": {
    "postbuild": "node postbuild.js"
},
相关推荐
天平20 小时前
油猴脚本创建webworker踩坑记录
前端·javascript·typescript
原则猫1 天前
前端基础大厦
前端
陈随易1 天前
编程语言级别的Skill市场,AI Agent 的未来形态
前端·后端·程序员
SoaringHeart1 天前
Flutter进阶:基于 EasyRefresh 的下拉刷新封装 n_easy_refresh_mixin.dart
前端·flutter
IT_陈寒1 天前
Vite的热更新突然不香了,排查三小时差点砸键盘
前端·人工智能·后端
子兮曰1 天前
Agency-Agents 深度解析:400+ AI 专家的"梦之队"如何重塑开发工作流
前端·后端·vibecoding
山河木马1 天前
渲染管线-计算得到gl_Position(顶点着色器)之后续GPU流程
javascript·webgl·图形学
竹林8181 天前
用 The Graph 查询链上数据实战:从手搓 RPC 到 Subgraph,我的 NFT 项目数据加载快了 10 倍
前端·javascript
妙码生花1 天前
从 PHP 到 AI + Golang,程序员自救转型手记(十九):点选验证码代码逐行目检
前端·后端·go
Awu12271 天前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统
前端·人工智能·claude