Vue反编译dist包到源码

1,如何反编译

1.首先需要在管理员模式下打开cmd

2.找到需要编译的dist/static/js的目录下 执行完成后在该目录会看到目录下存在下面的文件名:

0.7ab7d1434ffcc747c1ca.js.map,这里以0.7ab7d1434ffcc747c1ca.js.map为例,如下图:

3.全局安装reverse-sourcemap资源

npm install --global reverse-sourcemap4.反编译 执行:reverse-sourcemap --output-dir source

0.7ab7d1434ffcc747c1ca.js.map

2,脚本反编译

上面的方式执行完毕,确实在source中会出现源码,那么有没有可能用脚本去执行呢,通过node的child_process模块中的exec方式便可以执行reverse-sourcemap --output-dir source这个命令,那么只需要拿到当前文件夹中包含.map文件即可,那么可以借助node中fs模块,递归读取文件名,并使用正则将所有.map的文件提取出来放在一个集合或数组中,在对数组进行递归循环执行reverse-sourcemap --output-dir source这个命令

2.1 根据child_process模块编写执行函数

function executeReverseSourceMap(outputDir) {    // 构建 reverse-sourcemap 命令    const command = `reverse-sourcemap --output-dir source ${outputDir}`;    // 执行命令    exec(command, (error, stdout, stderr) => {      if (error) {        console.error(`执行命令时出错:${error.message}`);        return;      }      if (stderr) {        console.error(`命令输出错误:${stderr}`);        return;      }      console.log(`命令输出结果:${stdout}`);    });  }

2.2读取文件并匹配文件

// // 读取文件夹中的文件fs.readdir(folderPath, (err, files) => {  if (err) {    console.error('读取文件夹时出错:', err);    return;  }  // 遍历文件  files.forEach(file => {    // 使用正则表达式匹配特定格式的文件名    const match = /^(\d+)\..+\.js\.map$/.exec(file);    if (match) {      // 如果匹配成功,将文件名存入数组      targetFiles.push(match[0]);    }  });  // 输出目标文件名数组  targetFiles.forEach(file=>{    executeReverseSourceMap(file)  })});

2.3完整的执行代码

const fs = require('fs');const path = require('path');const { exec } = require('child_process');// 文件夹路径const folderPath = '../js';// 存放目标文件名的数组const targetFiles = [];function executeReverseSourceMap(outputDir) {    // 构建 reverse-sourcemap 命令    const command = `reverse-sourcemap --output-dir source ${outputDir}`;    // 执行命令    exec(command, (error, stdout, stderr) => {      if (error) {        console.error(`执行命令时出错:${error.message}`);        return;      }      if (stderr) {        console.error(`命令输出错误:${stderr}`);        return;      }      console.log(`命令输出结果:${stdout}`);    });  }// // 读取文件夹中的文件fs.readdir(folderPath, (err, files) => {  if (err) {    console.error('读取文件夹时出错:', err);    return;  }  // 遍历文件  files.forEach(file => {    // 使用正则表达式匹配特定格式的文件名    const match = /^(\d+)\..+\.js\.map$/.exec(file);    if (match) {      // 如果匹配成功,将文件名存入数组      targetFiles.push(match[0]);    }  });  // 输出目标文件名数组  targetFiles.forEach(file=>{    executeReverseSourceMap(file)  })});

图片

3,最终结果展示图

### 打包 Vue 项目 为了将 Vue 项目部署至阿里云服务器,首先需确保本地开发环境中的 Vue 项目能够正常构建。通过命令行工具执行 `npm run build` 或者 `yarn build` 命令可以触发项目的打包过程[^4]。 ```bash npm run build ``` 上述命令将会依据配置自动编译源码,并优化资源以便于生产环境中使用,最终生成的静态文件会被放置在一个名为 `dist/` 的目录内,该目录含了用于上线发布的全部必要文件,如 HTML 文件、JavaScript 文件以及其他静态资产等。 ### 将打包好的 Vue 应用上传到远程服务器 #### 准备工作 - 使用 FinalShell 等 SSH 工具连接已购入的 CentOS 系统下的阿里云实例[^1]。 - 开启必要的网络端口,在安全组设置里允许外部访问 Web 服务所需的 HTTP (80) 及 HTTPS (443) 协议对应的默认端口号;如果应用监听的是其他自定义端口也应相应放开这些端口[^2]。 #### 部署流程 一旦完成了以上准备工作之后,就可以着手准备传输之前提到过的 `dist/` 文件夹了: 一种常见的方式是借助 Git 版本控制系统或是 SCP/SFTP 来实现文件同步操作。对于小型站点来说,直接利用 FTP 客户端亦可满足需求。不过更推荐的做法是在目标机器上安装 Node.js 并全局装设 pm2 进程管理器来启动单页应用程序(SPA),从而简化运维管理工作流[^5]。 另一种方式则是采用 Nginx 作为反向代理服务器来提供静态页面加载支持。具体做法如下所示: 编辑 `/etc/nginx/conf.d/default.conf` 添加如下内容以适配实际应用场景的需求: ```nginx server { listen 80; server_name your_domain.com; location / { root /path/to/dist; # 替换成你自己的路径 index index.html index.htm; try_files $uri $uri/ /index.html; } } ``` 最后一步就是重启 Nginx 让更改生效: ```bash sudo systemctl restart nginx ``` 此时应该就能顺利浏览由 Vue 构建出来的前端界面啦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值