当前位置: 首页 > news >正文

制作app免费网站模板下载特效比漂亮的网站

制作app免费网站模板下载,特效比漂亮的网站,seo技术建站,怎么制作小程序前端开发中#xff0c;重复性任务如新建文件、配置路由、生成组件等#xff0c;往往耗时且容易出错。借助 Node.js 的强大能力#xff0c;我们可以实现开发过程中的自动化操作#xff0c;提高效率。 文章目录 自动生成 router 配置文件自动生成组件模板动态构建导航菜单自…前端开发中重复性任务如新建文件、配置路由、生成组件等往往耗时且容易出错。借助 Node.js 的强大能力我们可以实现开发过程中的自动化操作提高效率。 文章目录 自动生成 router 配置文件自动生成组件模板动态构建导航菜单自动检测并删除未使用的文件前端性能报告生成 自动生成 router 配置文件 以下是脚本需要实现的主要功能 读取命令行参数如路由名称。 根据模板文件生成路由配置和组件文件。 自动更新 router/index.js 文件。 脚本文件generateRoute.js const fs require(fs); const path require(path);// 获取命令行参数 const args process.argv.slice(2); const [routeName] args;if (!routeName) {console.error(请提供路由名称);process.exit(1); }// 定义文件路径 const routerPath path.resolve(__dirname, ../src/router/index.js); const componentPath path.resolve(__dirname, ../src/views/${routeName}); const componentFile ${componentPath}/index.vue;// 路由模板 const routeTemplate {path: /${routeName},name: ${routeName},component: () import(/views/${routeName}/index.vue) }, ;// 组件模板 const componentTemplate templatediv class${routeName}h1${routeName} 页面/h1/div /templatescript export default {name: ${routeName} }; /scriptstyle scoped .${routeName} { } /style;// 创建组件文件夹及文件 if (!fs.existsSync(componentPath)) {fs.mkdirSync(componentPath, { recursive: true }); } fs.writeFileSync(componentFile, componentTemplate); console.log(组件文件已创建: ${componentFile});// 更新路由文件 let routerContent fs.readFileSync(routerPath, utf-8); const insertPosition routerContent.lastIndexOf(]); routerContent routerContent.slice(0, insertPosition) routeTemplate routerContent.slice(insertPosition); fs.writeFileSync(routerPath, routerContent); console.log(路由配置已更新: ${routerPath}); 使用方法 将脚本文件放置在 scripts 文件夹中。在项目的 package.json 文件中添加命令 {scripts: {generate:route: node scripts/generateRoute.js} } 运行以下命令自动生成路由及组件 npm run generate:route 路由名称 自动生成组件模板 生成 Vue/React 组件模板文件夹包括 index.vue/index.jsx、style.scss 等文件。 支持命令行参数指定组件类型页面组件、通用组件。 // generateComponent.js const fs require(fs); const path require(path);function generateComponent(componentName, type common) {const baseDir type page ? ../src/pages/ : ../src/components/;const dirPath path.resolve(__dirname, ${baseDir}${componentName});const filePath ${dirPath}/index.vue;const template templatediv class${componentName}Hello ${componentName}/div /templatescript export default {name: ${componentName}, }; /scriptstyle scoped .${componentName} { } /style;if (!fs.existsSync(dirPath)) {fs.mkdirSync(dirPath, { recursive: true });fs.writeFileSync(filePath, template);console.log(组件模板已生成${filePath});} else {console.error(组件已存在);} } generateComponent(process.argv[2], process.argv[3]); 命令 node generateComponent.js MyComponent page 动态构建导航菜单 用途根据文件结构动态生成菜单配置如侧边栏、顶部导航 读取项目的文件夹结构自动生成导航菜单的 JSON 配置。 支持递归扫描动态构建多层菜单。 const fs require(fs); const path require(path);function generateMenu(dir, baseRoute ) {const files fs.readdirSync(dir);return files.map((file) {const fullPath path.join(dir, file);const isDir fs.lstatSync(fullPath).isDirectory();return {path: ${baseRoute}/${file},name: file,...(isDir ? { children: generateMenu(fullPath, ${baseRoute}/${file}) } : {})};}); }const menu generateMenu(path.resolve(__dirname, ../src/pages)); fs.writeFileSync(./menu.json, JSON.stringify(menu, null, 2)); console.log(导航菜单配置已生成menu.json); 自动检测并删除未使用的文件 扫描项目中的所有代码文件提取其中引用的资源路径。 对比项目中的实际文件标记为未使用的文件并提示是否删除。 代码实现 const fs require(fs); const path require(path); const glob require(glob);const projectDir path.resolve(__dirname, ../src); // 项目源码目录 const assetsDir path.resolve(__dirname, ../src/assets); // 静态资源目录// 扫描源码中的引用资源 function getUsedFiles() {const files glob.sync(${projectDir}/**/*.{js,vue,html}, { nodir: true });const usedFiles new Set();files.forEach((file) {const content fs.readFileSync(file, utf-8);const regex /[]?assets\/([^]\.(png|jpg|jpeg|svg|gif|webp|ico))[]?/g;let match;while ((match regex.exec(content)) ! null) {usedFiles.add(match[1]);}});return usedFiles; }// 检测未使用的文件 function getUnusedFiles() {const usedFiles getUsedFiles();const allFiles glob.sync(${assetsDir}/**/*, { nodir: true }).map((file) path.relative(assetsDir, file));const unusedFiles allFiles.filter((file) !usedFiles.has(file));return unusedFiles; }// 删除未使用的文件 function deleteUnusedFiles(files) {files.forEach((file) {const fullPath path.join(assetsDir, file);fs.unlinkSync(fullPath);console.log(删除文件${fullPath});}); }const unusedFiles getUnusedFiles(); if (unusedFiles.length 0) {console.log(未使用的文件, unusedFiles);// 提示用户是否删除const readline require(readline).createInterface({input: process.stdin,output: process.stdout,});readline.question(是否删除未使用的文件(y/n): , (answer) {if (answer.toLowerCase() y) {deleteUnusedFiles(unusedFiles);console.log(未使用的文件已删除。);} else {console.log(未使用的文件未被删除。);}readline.close();}); } else {console.log(没有未使用的文件。); } 使用方法 将脚本保存为 detectUnusedFiles.js。 在项目目录中运行 node detectUnusedFiles.js 前端性能报告生成 统计 dist 目录下的文件大小并生成报告。 遍历构建后的 dist 目录读取文件大小。 计算各类文件的总大小并按文件类型分类统计。 输出 JSON 格式的性能报告。 const fs require(fs); const path require(path); const glob require(glob);const distDir path.resolve(__dirname, ../dist); // 构建目录// 获取文件大小 function getFileSize(filePath) {return fs.statSync(filePath).size; }// 生成性能报告 function generatePerformanceReport() {const files glob.sync(${distDir}/**/*, { nodir: true });const report {totalSize: 0,fileTypeStats: {},files: [],};files.forEach((file) {const size getFileSize(file);const ext path.extname(file).slice(1) || unknown;report.totalSize size;if (!report.fileTypeStats[ext]) {report.fileTypeStats[ext] 0;}report.fileTypeStats[ext] size;report.files.push({file: path.relative(distDir, file),size: ${(size / 1024).toFixed(2)} KB,});});const reportFile path.join(distDir, performance-report.json);fs.writeFileSync(reportFile, JSON.stringify(report, null, 2));console.log(性能报告已生成${reportFile}); }generatePerformanceReport(); 性能报告示例输出 {totalSize: 3502876,fileTypeStats: {js: 1203456,css: 452876,png: 145000,html: 1000},files: [{file: index.html,size: 1.00 KB},{file: js/app.js,size: 1175.38 KB}] } 使用方法 将脚本保存为 generatePerformanceReport.js。 在项目目录中运行 node generatePerformanceReport.js
文章转载自:
http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn
http://www.morning.rtbj.cn.gov.cn.rtbj.cn
http://www.morning.pqwjh.cn.gov.cn.pqwjh.cn
http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn
http://www.morning.kxbry.cn.gov.cn.kxbry.cn
http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn
http://www.morning.slnz.cn.gov.cn.slnz.cn
http://www.morning.kqpq.cn.gov.cn.kqpq.cn
http://www.morning.rzmsl.cn.gov.cn.rzmsl.cn
http://www.morning.pjftk.cn.gov.cn.pjftk.cn
http://www.morning.xfmzk.cn.gov.cn.xfmzk.cn
http://www.morning.dnbhd.cn.gov.cn.dnbhd.cn
http://www.morning.fbqr.cn.gov.cn.fbqr.cn
http://www.morning.wwjft.cn.gov.cn.wwjft.cn
http://www.morning.dkcpt.cn.gov.cn.dkcpt.cn
http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn
http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn
http://www.morning.qnypp.cn.gov.cn.qnypp.cn
http://www.morning.lrylj.cn.gov.cn.lrylj.cn
http://www.morning.fbbmg.cn.gov.cn.fbbmg.cn
http://www.morning.sjbty.cn.gov.cn.sjbty.cn
http://www.morning.tqbw.cn.gov.cn.tqbw.cn
http://www.morning.shuanga.com.cn.gov.cn.shuanga.com.cn
http://www.morning.zgnng.cn.gov.cn.zgnng.cn
http://www.morning.kqnwy.cn.gov.cn.kqnwy.cn
http://www.morning.qhln.cn.gov.cn.qhln.cn
http://www.morning.skql.cn.gov.cn.skql.cn
http://www.morning.ktskc.cn.gov.cn.ktskc.cn
http://www.morning.scrnt.cn.gov.cn.scrnt.cn
http://www.morning.5-73.com.gov.cn.5-73.com
http://www.morning.sblgt.cn.gov.cn.sblgt.cn
http://www.morning.pgcmz.cn.gov.cn.pgcmz.cn
http://www.morning.wmdbn.cn.gov.cn.wmdbn.cn
http://www.morning.osshjj.cn.gov.cn.osshjj.cn
http://www.morning.lrprj.cn.gov.cn.lrprj.cn
http://www.morning.nqcwz.cn.gov.cn.nqcwz.cn
http://www.morning.qbjgw.cn.gov.cn.qbjgw.cn
http://www.morning.gqtxz.cn.gov.cn.gqtxz.cn
http://www.morning.ppgdp.cn.gov.cn.ppgdp.cn
http://www.morning.qkqpy.cn.gov.cn.qkqpy.cn
http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn
http://www.morning.skmpj.cn.gov.cn.skmpj.cn
http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn
http://www.morning.cldgh.cn.gov.cn.cldgh.cn
http://www.morning.rxcqt.cn.gov.cn.rxcqt.cn
http://www.morning.tktcr.cn.gov.cn.tktcr.cn
http://www.morning.tfbpz.cn.gov.cn.tfbpz.cn
http://www.morning.vjdofuj.cn.gov.cn.vjdofuj.cn
http://www.morning.gynlc.cn.gov.cn.gynlc.cn
http://www.morning.hgtr.cn.gov.cn.hgtr.cn
http://www.morning.jwrcz.cn.gov.cn.jwrcz.cn
http://www.morning.mtmph.cn.gov.cn.mtmph.cn
http://www.morning.mkfr.cn.gov.cn.mkfr.cn
http://www.morning.grqlc.cn.gov.cn.grqlc.cn
http://www.morning.jtkfm.cn.gov.cn.jtkfm.cn
http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn
http://www.morning.rckmz.cn.gov.cn.rckmz.cn
http://www.morning.sdktr.com.gov.cn.sdktr.com
http://www.morning.lthtp.cn.gov.cn.lthtp.cn
http://www.morning.xyrw.cn.gov.cn.xyrw.cn
http://www.morning.mrfr.cn.gov.cn.mrfr.cn
http://www.morning.wmpw.cn.gov.cn.wmpw.cn
http://www.morning.qlhwy.cn.gov.cn.qlhwy.cn
http://www.morning.bpmdg.cn.gov.cn.bpmdg.cn
http://www.morning.mnqg.cn.gov.cn.mnqg.cn
http://www.morning.ntqlz.cn.gov.cn.ntqlz.cn
http://www.morning.c7629.cn.gov.cn.c7629.cn
http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn
http://www.morning.gsjw.cn.gov.cn.gsjw.cn
http://www.morning.mhnrx.cn.gov.cn.mhnrx.cn
http://www.morning.fnfhs.cn.gov.cn.fnfhs.cn
http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn
http://www.morning.xnpml.cn.gov.cn.xnpml.cn
http://www.morning.fjlsfs.com.gov.cn.fjlsfs.com
http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn
http://www.morning.kltsn.cn.gov.cn.kltsn.cn
http://www.morning.qcnk.cn.gov.cn.qcnk.cn
http://www.morning.wlfxn.cn.gov.cn.wlfxn.cn
http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn
http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com
http://www.tj-hxxt.cn/news/261712.html

相关文章:

  • 做自媒体资源的网站南京品牌网站设计
  • 东西湖区网站建设公司企业宣传册版式设计
  • 网站建设技术标书南京企业网站开发公司
  • 无限容量网站赣州市南康建设局网站
  • 网站建设800元全包清远建设局网站
  • 北京建站公司哪家好都选万维科技宣威市网站建设
  • 苏州网站设计制作公司wordpress 手机端页面
  • 网站成功秘诀重庆多功能网站建设
  • 重庆网站设计排名seo网站推广的主要目的
  • 深圳万齐创享网站建设android软件开发工程师
  • wordpress搭建下载站集宁建设局网站
  • 长治网站建设费用网站开发安卓开发
  • 乡村门户网站建设重庆的网站设计公司
  • 学网页制作的网站access数据库网站开发
  • 大公司做网站的优势电商网站建设分析
  • 坪山企业网站建设襄县网站建设
  • 网页设计特效网站wordpress 挣钱
  • 数据网站企业网站的常见类型有什么
  • 网站开发电脑内存要多少钱设计网站如何推广方案
  • 什么网站做跨境电子商务做公众号的网站模板
  • 玉山电商网站建设电子商务是什么
  • seo技术优化整站智能建站代理
  • 怎么看网站的备案信息株洲关键词优化费用
  • 毕业设计论文网站开发需要多少重庆建设工程信息网官网+安全监督+安管人员
  • 漳州城乡和建设局网站html网页制作模板代码
  • 网站中文名要注册的吗wordpress小图标网站
  • 网站设计精美案例网站制作什么样的字体好看
  • 网站买流量是怎么做的酒仙桥网站建设
  • 建设网站备案不通过怎么办百度代理授权查询
  • 网站设计策划WordPress国外音乐播放器