{"id":33699,"date":"2024-11-25T13:11:55","date_gmt":"2024-11-25T05:11:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33699\/"},"modified":"2024-11-25T13:11:55","modified_gmt":"2024-11-25T05:11:55","slug":"%e4%bb%8b%e7%bb%8d%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%be%9d%e8%b5%96%e5%88%86%e6%9e%90%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33699\/","title":{"rendered":"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5"},"content":{"rendered":"<h2> \u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u3002<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/5fa121f888ba8648.jpg\" class=\"aligncenter\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe\" \/><\/p>\n<p>\u7528\u8fc7 webpack \u7684\u540c\u5b66\u80af\u5b9a\u77e5\u9053 webpack-bundle-analyzer \uff0c\u53ef\u4ee5\u7528\u6765\u5206\u6790\u5f53\u524d\u9879\u76ee js \u6587\u4ef6\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/459a8492264ba963052db2bcffab6a7d-0.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe1\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe1\" \/><\/p>\n<p>\u56e0\u4e3a\u6700\u8fd1\u4e00\u76f4\u5728\u505a\u5c0f\u7a0b\u5e8f\u4e1a\u52a1\uff0c\u800c\u4e14\u5c0f\u7a0b\u5e8f\u5bf9\u5305\u4f53\u5927\u5c0f\u7279\u522b\u654f\u611f\uff0c\u6240\u4ee5\u5c31\u60f3\u7740\u80fd\u4e0d\u80fd\u505a\u4e00\u4e2a\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u7528\u6765\u67e5\u770b\u5f53\u524d\u5c0f\u7a0b\u5e8f\u5404\u4e2a\u4e3b\u5305\u4e0e\u5206\u5305\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u3002\u7ecf\u8fc7\u51e0\u5929\u7684\u6298\u817e\u7ec8\u4e8e\u505a\u51fa\u6765\u4e86\uff0c\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/93765b83edba9c80b921856cb769dc08-1.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe2\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe2\" \/><\/p>\n<p>\u4eca\u5929\u7684\u6587\u7ae0\u5c31\u5e26\u5927\u5bb6\u6765\u5b9e\u73b0\u8fd9\u4e2a\u5de5\u5177\u3002<\/p>\n<h2>\u5c0f\u7a0b\u5e8f\u5165\u53e3<\/h2>\n<p>\u5c0f\u7a0b\u5e8f\u7684\u9875\u9762\u901a\u8fc7 app.json \u7684 pages \u53c2\u6570\u5b9a\u4e49\uff0c\u7528\u4e8e\u6307\u5b9a\u5c0f\u7a0b\u5e8f\u7531\u54ea\u4e9b\u9875\u9762\u7ec4\u6210\uff0c\u6bcf\u4e00\u9879\u90fd\u5bf9\u5e94\u4e00\u4e2a\u9875\u9762\u7684\u8def\u5f84\uff08\u542b\u6587\u4ef6\u540d\uff09 \u4fe1\u606f\u3002 pages \u5185\u7684\u6bcf\u4e2a\u9875\u9762\uff0c\u5c0f\u7a0b\u5e8f\u90fd\u4f1a\u53bb\u5bfb\u627e\u5bf9\u5e94\u7684 json, js, wxml, wxss \u56db\u4e2a\u6587\u4ef6\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u5982\u5f00\u53d1\u76ee\u5f55\u4e3a\uff1a<\/p>\n<pre>\u251c\u2500\u2500 app.js\n\u251c\u2500\u2500 app.json\n\u251c\u2500\u2500 app.wxss\n\u251c\u2500\u2500 pages\n\u2502   \u2502\u2500\u2500 index\n\u2502   \u2502   \u251c\u2500\u2500 index.wxml\n\u2502   \u2502   \u251c\u2500\u2500 index.js\n\u2502   \u2502   \u251c\u2500\u2500 index.json\n\u2502   \u2502   \u2514\u2500\u2500 index.wxss\n\u2502   \u2514\u2500\u2500 logs\n\u2502       \u251c\u2500\u2500 logs.wxml\n\u2502       \u2514\u2500\u2500 logs.js\n\u2514\u2500\u2500 utils\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5219\u9700\u8981\u5728 app.json \u4e2d\u5199\uff1a<\/p>\n<pre>{  \"pages\": [\"pages\/index\/index\", \"pages\/logs\/logs\"]\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u6f14\u793a\uff0c\u6211\u4eec\u5148 fork \u4e00\u4efd\u5c0f\u7a0b\u5e8f\u7684\u5b98\u65b9demo\uff0c\u7136\u540e\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6 depend.js\uff0c\u4f9d\u8d56\u5206\u6790\u76f8\u5173\u7684\u5de5\u4f5c\u5c31\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\u5b9e\u73b0\u3002<\/p>\n<pre>$ git clone git@github.com:wechat-miniprogram\/miniprogram-demo.git\n$ cd miniprogram-demo\n$ touch depend.js\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u5927\u81f4\u7684\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/a43796849389d1d23bbfe565673ffa34-2.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe3\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe3\" \/><\/p>\n<p>\u4ee5 app.json \u4e3a\u5165\u53e3\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u6240\u6709\u4e3b\u5305\u4e0b\u7684\u9875\u9762\u3002<\/p>\n<pre>const fs = require('fs-extra')const path = require('path')const root = process.cwd()class Depend {  constructor() {    this.context = path.join(root, 'miniprogram')\n  }  \/\/ \u83b7\u53d6\u7edd\u5bf9\u5730\u5740\n  getAbsolute(file) {    return path.join(this.context, file)\n  }  run() {    const appPath = this.getAbsolute('app.json')    const appJson = fs.readJsonSync(appPath)    const { pages } = appJson \/\/ \u4e3b\u5305\u7684\u6240\u6709\u9875\u9762\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6bcf\u4e2a\u9875\u9762\u4f1a\u5bf9\u5e94 json, js, wxml, wxss \u56db\u4e2a\u6587\u4ef6\uff1a<\/p>\n<pre>const Extends = ['.js', '.json', '.wxml', '.wxss']class Depend {  constructor() {    \/\/ \u5b58\u50a8\u6587\u4ef6\n    this.files = new Set()    this.context = path.join(root, 'miniprogram')\n  }  \/\/ \u4fee\u6539\u6587\u4ef6\u540e\u7f00\n  replaceExt(filePath, ext = '') {    const dirName = path.dirname(filePath)    const extName = path.extname(filePath)    const fileName = path.basename(filePath, extName)    return path.join(dirName, fileName + ext)\n  }  run() {    \/\/ \u7701\u7565\u83b7\u53d6 pages \u8fc7\u7a0b\n    pages.forEach(page =&gt; {      \/\/ \u83b7\u53d6\u7edd\u5bf9\u5730\u5740\n      const absPath = this.getAbsolute(page)\n      Extends.forEach(ext =&gt; {        \/\/ \u6bcf\u4e2a\u9875\u9762\u90fd\u9700\u8981\u5224\u65ad js\u3001json\u3001wxml\u3001wxss \u662f\u5426\u5b58\u5728\n        const filePath = this.replaceExt(absPath, ext)        if (fs.existsSync(filePath)) {          this.files.add(filePath)\n        }\n      })\n    })\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728 pages \u5185\u9875\u9762\u76f8\u5173\u7684\u6587\u4ef6\u90fd\u653e\u5230 files \u5b57\u6bb5\u5b58\u8d77\u6765\u4e86\u3002<\/p>\n<h2>\u6784\u9020\u6811\u5f62\u7ed3\u6784<\/h2>\n<p>\u62ff\u5230\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u9700\u8981\u4f9d\u636e\u5404\u4e2a\u6587\u4ef6\u6784\u9020\u4e00\u4e2a\u6811\u5f62\u7ed3\u6784\u7684\u6587\u4ef6\u6811\uff0c\u7528\u4e8e\u540e\u7eed\u5c55\u793a\u4f9d\u8d56\u5173\u7cfb\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a pages \u76ee\u5f55\uff0cpages \u76ee\u5f55\u4e0b\u6709\u4e24\u4e2a\u9875\u9762\uff1adetail\u3001index \uff0c\u8fd9\u4e24\u4e2a \u9875\u9762\u6587\u4ef6\u5939\u4e0b\u6709\u56db\u4e2a\u5bf9\u5e94\u7684\u6587\u4ef6\u3002<\/p>\n<pre>pages\n\u251c\u2500\u2500 detail\n\u2502   \u251c\u2500\u2500 detail.js\n\u2502   \u251c\u2500\u2500 detail.json\n\u2502   \u251c\u2500\u2500 detail.wxml\n\u2502   \u2514\u2500\u2500 detail.wxss\n\u2514\u2500\u2500 index\n    \u251c\u2500\u2500 index.js\n    \u251c\u2500\u2500 index.json\n    \u251c\u2500\u2500 index.wxml\n    \u2514\u2500\u2500 index.wxss\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f9d\u636e\u4e0a\u9762\u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u6211\u4eec\u6784\u9020\u4e00\u4e2a\u5982\u4e0b\u7684\u6587\u4ef6\u6811\u7ed3\u6784\uff0csize \u7528\u4e8e\u8868\u793a\u5f53\u524d\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u7684\u5927\u5c0f\uff0cchildren \u5b58\u653e\u6587\u4ef6\u5939\u4e0b\u7684\u6587\u4ef6\uff0c\u5982\u679c\u662f\u6587\u4ef6\u5219\u6ca1\u6709 children \u5c5e\u6027\u3002<\/p>\n<pre>pages = {  \"size\": 8,  \"children\": {    \"detail\": {      \"size\": 4,      \"children\": {        \"detail.js\": { \"size\": 1 },        \"detail.json\": { \"size\": 1 },        \"detail.wxml\": { \"size\": 1 },        \"detail.wxss\": { \"size\": 1 }\n      }\n    },    \"index\": {      \"size\": 4,      \"children\": {        \"index.js\": { \"size\": 1 },        \"index.json\": { \"size\": 1 },        \"index.wxml\": { \"size\": 1 },        \"index.wxss\": { \"size\": 1 }\n      }\n    }\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u5148\u5728\u6784\u9020\u51fd\u6570\u6784\u9020\u4e00\u4e2a tree \u5b57\u6bb5\u7528\u6765\u5b58\u50a8\u6587\u4ef6\u6811\u7684\u6570\u636e\uff0c\u7136\u540e\u6211\u4eec\u5c06\u6bcf\u4e2a\u6587\u4ef6\u90fd\u4f20\u5165 addToTree \u65b9\u6cd5\uff0c\u5c06\u6587\u4ef6\u6dfb\u52a0\u5230\u6811\u4e2d \u3002<\/p>\n<pre>class Depend {  constructor() {    this.tree = {      size: 0,      children: {}\n    }    this.files = new Set()    this.context = path.join(root, 'miniprogram')\n  }  \n  run() {    \/\/ \u7701\u7565\u83b7\u53d6 pages \u8fc7\u7a0b\n    pages.forEach(page =&gt; {      const absPath = this.getAbsolute(page)\n      Extends.forEach(ext =&gt; {        const filePath = this.replaceExt(absPath, ext)        if (fs.existsSync(filePath)) {          \/\/ \u8c03\u7528 addToTree\n          this.addToTree(filePath)\n        }\n      })\n    })\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u63a5\u4e0b\u6765\u5b9e\u73b0 addToTree \u65b9\u6cd5\uff1a<\/p>\n<pre>class Depend {  \/\/ \u7701\u7565\u4e4b\u524d\u7684\u90e8\u5206\u4ee3\u7801\n\n  \/\/ \u83b7\u53d6\u76f8\u5bf9\u5730\u5740\n  getRelative(file) {    return path.relative(this.context, file)\n  }  \/\/ \u83b7\u53d6\u6587\u4ef6\u5927\u5c0f\uff0c\u5355\u4f4d KB\n  getSize(file) {    const stats = fs.statSync(file)    return stats.size \/ 1024\n  }  \/\/ \u5c06\u6587\u4ef6\u6dfb\u52a0\u5230\u6811\u4e2d\n  addToTree(filePath) {    if (this.files.has(filePath)) {      \/\/ \u5982\u679c\u8be5\u6587\u4ef6\u5df2\u7ecf\u6dfb\u52a0\u8fc7\uff0c\u5219\u4e0d\u518d\u6dfb\u52a0\u5230\u6587\u4ef6\u6811\u4e2d\n      return\n    }    const size = this.getSize(filePath)    const relPath = this.getRelative(filePath)    \/\/ \u5c06\u6587\u4ef6\u8def\u5f84\u8f6c\u5316\u6210\u6570\u7ec4\n    \/\/ 'pages\/index\/index.js' =&gt;\n    \/\/ ['pages', 'index', 'index.js']\n    const names = relPath.split(path.sep)    const lastIdx = names.length - 1\n\n    this.tree.size += size    let point = this.tree.children\n    names.forEach((name, idx) =&gt; {      if (idx === lastIdx) {\n        point[name] = { size }        return\n      }      if (!point[name]) {\n        point[name] = {\n          size, children: {}\n        }\n      } else {\n        point[name].size += size\n      }\n      point = point[name].children\n    })    \/\/ \u5c06\u6587\u4ef6\u6dfb\u52a0\u7684 files\n    this.files.add(filePath)\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728\u8fd0\u884c\u4e4b\u540e\uff0c\u5c06\u6587\u4ef6\u8f93\u51fa\u5230 tree.json \u770b\u770b\u3002<\/p>\n<pre> run() {   \/\/ ...\n   pages.forEach(page =&gt; {     \/\/...\n   })\n   fs.writeJSONSync('tree.json', this.tree, { spaces: 2 })\n }\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/d1027296a3eafc6a3805451b6d9ef634-3.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe4\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe4\" \/><\/p>\n<h2>\u83b7\u53d6\u4f9d\u8d56\u5173\u7cfb<\/h2>\n<p>\u4e0a\u9762\u7684\u6b65\u9aa4\u770b\u8d77\u6765\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u662f\u6211\u4eec\u7f3a\u5c11\u4e86\u91cd\u8981\u7684\u4e00\u73af\uff0c\u90a3\u5c31\u662f\u6211\u4eec\u5728\u6784\u9020\u6587\u4ef6\u6811\u4e4b\u524d\uff0c\u8fd8\u9700\u8981\u5f97\u5230\u6bcf\u4e2a\u6587\u4ef6\u7684\u4f9d\u8d56\u9879\uff0c\u8fd9\u6837\u8f93\u51fa\u7684\u624d\u662f\u5c0f\u7a0b\u5e8f\u5b8c\u6574\u7684\u6587\u4ef6\u6811\u3002\u6587\u4ef6\u7684\u4f9d\u8d56\u5173\u7cfb\u9700\u8981\u5206\u6210\u56db\u90e8\u5206\u6765\u8bb2\uff0c\u5206\u522b\u662f &nbsp;js, json, wxml, wxss &nbsp;\u8fd9\u56db\u79cd\u7c7b\u578b\u6587\u4ef6\u83b7\u53d6\u4f9d\u8d56\u7684\u65b9\u5f0f\u3002<\/p>\n<h3>\u83b7\u53d6 .js \u6587\u4ef6\u4f9d\u8d56<\/h3>\n<p>\u5c0f\u7a0b\u5e8f\u652f\u6301 CommonJS \u7684\u65b9\u5f0f\u8fdb\u884c\u6a21\u5757\u5316\uff0c\u5982\u679c\u5f00\u542f\u4e86 es6\uff0c\u4e5f\u80fd\u652f\u6301 ESM \u8fdb\u884c\u6a21\u5757\u5316\u3002\u6211\u4eec\u5982\u679c\u8981\u83b7\u5f97\u4e00\u4e2a js \u6587\u4ef6\u7684\u4f9d\u8d56\uff0c\u9996\u5148\u8981\u660e\u786e\uff0cjs \u6587\u4ef6\u5bfc\u5165\u6a21\u5757\u7684\u4e09\u79cd\u5199\u6cd5\uff0c\u9488\u5bf9\u4e0b\u9762\u4e09\u79cd\u8bed\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5f15\u5165 Babel \u6765\u83b7\u53d6\u4f9d\u8d56\u3002<\/p>\n<pre>import a from '.\/a.js'export b from '.\/b.js'const c = require('.\/c.js')\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7 @babel\/parser \u5c06\u4ee3\u7801\u8f6c\u5316\u4e3a AST\uff0c\u7136\u540e\u901a\u8fc7 @babel\/traverse \u904d\u5386 AST \u8282\u70b9\uff0c\u83b7\u53d6\u4e0a\u9762\u4e09\u79cd\u5bfc\u5165\u65b9\u5f0f\u7684\u503c\uff0c\u653e\u5230\u6570\u7ec4\u3002<\/p>\n<pre>const { parse } = require('@babel\/parser')const { default: traverse } = require('@babel\/traverse')class Depend {  \/\/ ...\n\tjsDeps(file) {    const deps = []    const dirName = path.dirname(file)    \/\/ \u8bfb\u53d6 js \u6587\u4ef6\u5185\u5bb9\n    const content = fs.readFileSync(file, 'utf-8')    \/\/ \u5c06\u4ee3\u7801\u8f6c\u5316\u4e3a AST\n    const ast = parse(content, {      sourceType: 'module',      plugins: ['exportDefaultFrom']\n    })    \/\/ \u904d\u5386 AST\n    traverse(ast, {      ImportDeclaration: ({ node }) =&gt; {        \/\/ \u83b7\u53d6 import from \u5730\u5740\n        const { value } = node.source        const jsFile = this.transformScript(dirName, value)        if (jsFile) {\n          deps.push(jsFile)\n        }\n      },      ExportNamedDeclaration: ({ node }) =&gt; {        \/\/ \u83b7\u53d6 export from \u5730\u5740\n        const { value } = node.source        const jsFile = this.transformScript(dirName, value)        if (jsFile) {\n          deps.push(jsFile)\n        }\n      },      CallExpression: ({ node }) =&gt; {        if (\n          (node.callee.name &amp;&amp; node.callee.name === 'require') &amp;&amp;\n          node.arguments.length &gt;= 1\n        ) {          \/\/ \u83b7\u53d6 require \u5730\u5740\n          const [{ value }] = node.arguments          const jsFile = this.transformScript(dirName, value)          if (jsFile) {\n            deps.push(jsFile)\n          }\n        }\n      }\n    })    return deps\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u83b7\u53d6\u4f9d\u8d56\u6a21\u5757\u7684\u8def\u5f84\u540e\uff0c\u8fd8\u4e0d\u80fd\u7acb\u5373\u5c06\u8def\u5f84\u6dfb\u52a0\u5230\u4f9d\u8d56\u6570\u7ec4\u5185\uff0c\u56e0\u4e3a\u6839\u636e\u6a21\u5757\u8bed\u6cd5 js \u540e\u7f00\u662f\u53ef\u4ee5\u7701\u7565\u7684\uff0c\u53e6\u5916 require \u7684\u8def\u5f84\u662f\u4e00\u4e2a\u6587\u4ef6\u5939\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u4f1a\u5bfc\u5165\u8be5\u6587\u4ef6\u5939\u4e0b\u7684 index.js \u3002<\/p>\n<pre>class Depend {  \/\/ \u83b7\u53d6\u67d0\u4e2a\u8def\u5f84\u7684\u811a\u672c\u6587\u4ef6\n  transformScript(url) {    const ext = path.extname(url)    \/\/ \u5982\u679c\u5b58\u5728\u540e\u7f00\uff0c\u8868\u793a\u5f53\u524d\u5df2\u7ecf\u662f\u4e00\u4e2a\u6587\u4ef6\n    if (ext === '.js' &amp;&amp; fs.existsSync(url)) {      return url\n    }    \/\/ a\/b\/c =&gt; a\/b\/c.js\n    const jsFile = url + '.js'\n    if (fs.existsSync(jsFile)) {      return jsFile\n    }    \/\/ a\/b\/c =&gt; a\/b\/c\/index.js\n    const jsIndexFile = path.join(url, 'index.js')    if (fs.existsSync(jsIndexFile)) {      return jsIndexFile\n    }    return null\n  }\tjsDeps(file) {...}\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a js\uff0c\u770b\u770b\u8f93\u51fa\u7684 deps \u662f\u5426\u6b63\u786e\uff1a<\/p>\n<pre>\/\/ \u6587\u4ef6\u8def\u5f84\uff1a\/Users\/shenfq\/Code\/fork\/miniprogram-demo\/import a from '.\/a.js'export b from '..\/b.js'const c = require('..\/..\/c.js')\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/d1027296a3eafc6a3805451b6d9ef634-4.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe5\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe5\" \/><\/p>\n<h3>\u83b7\u53d6 .json \u6587\u4ef6\u4f9d\u8d56<\/h3>\n<p>json \u6587\u4ef6\u672c\u8eab\u662f\u4e0d\u652f\u6301\u6a21\u5757\u5316\u7684\uff0c\u4f46\u662f\u5c0f\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7 json \u6587\u4ef6\u5bfc\u5165\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u53ea\u9700\u8981\u5728\u9875\u9762\u7684 json \u6587\u4ef6\u901a\u8fc7 usingComponents \u8fdb\u884c\u5f15\u7528\u58f0\u660e\u3002usingComponents \u4e3a\u4e00\u4e2a\u5bf9\u8c61\uff0c\u952e\u4e3a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u7684\u6807\u7b7e\u540d\uff0c\u503c\u4e3a\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u6587\u4ef6\u8def\u5f84\uff1a<\/p>\n<pre>{  \"usingComponents\": {    \"component-tag-name\": \"path\/to\/the\/custom\/component\"\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u81ea\u5b9a\u4e49\u7ec4\u4ef6\u4e0e\u5c0f\u7a0b\u5e8f\u9875\u9762\u4e00\u6837\uff0c\u4e5f\u4f1a\u5bf9\u5e94\u56db\u4e2a\u6587\u4ef6\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u83b7\u53d6 json \u4e2d usingComponents \u5185\u7684\u6240\u6709\u4f9d\u8d56\u9879\uff0c\u5e76\u5224\u65ad\u6bcf\u4e2a\u7ec4\u4ef6\u5bf9\u5e94\u7684\u90a3\u56db\u4e2a\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u7136\u540e\u6dfb\u52a0\u5230\u4f9d\u8d56\u9879\u5185\u3002<\/p>\n<pre>class Depend {  \/\/ ...\n  jsonDeps(file) {    const deps = []    const dirName = path.dirname(file)    const { usingComponents } = fs.readJsonSync(file)    if (usingComponents &amp;&amp; typeof usingComponents === 'object') {      Object.values(usingComponents).forEach((component) =&gt; {\n        component = path.resolve(dirName, component)        \/\/ \u6bcf\u4e2a\u7ec4\u4ef6\u90fd\u9700\u8981\u5224\u65ad js\/json\/wxml\/wxss \u6587\u4ef6\u662f\u5426\u5b58\u5728\n        Extends.forEach((ext) =&gt; {          const file = this.replaceExt(component, ext)          if (fs.existsSync(file)) {\n            deps.push(file)\n          }\n        })\n      })\n    }    return deps\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u83b7\u53d6 .wxml \u6587\u4ef6\u4f9d\u8d56<\/h3>\n<p>wxml \u63d0\u4f9b\u4e24\u79cd\u6587\u4ef6\u5f15\u7528\u65b9\u5f0f import \u548c include\u3002<\/p>\n<pre>&lt;import src=\"a.wxml\"\/&gt;&lt;include src=\"b.wxml\"\/&gt;\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>wxml \u6587\u4ef6\u672c\u8d28\u4e0a\u8fd8\u662f\u4e00\u4e2a html \u6587\u4ef6\uff0c\u6240\u4ee5\u53ef\u4ee5\u901a\u8fc7 html parser \u5bf9 wxml \u6587\u4ef6\u8fdb\u884c\u89e3\u6790\uff0c\u5173\u4e8e html parser \u76f8\u5173\u7684\u539f\u7406\u53ef\u4ee5\u770b\u6211\u4e4b\u524d\u5199\u8fc7\u7684\u6587\u7ae0 &nbsp;\u300aVue \u6a21\u677f\u7f16\u8bd1\u539f\u7406\u300b\u3002<\/p>\n<pre>const htmlparser2 = require('htmlparser2')class Depend {  \/\/ ...\n\twxmlDeps(file) {    const deps = []    const dirName = path.dirname(file)    const content = fs.readFileSync(file, 'utf-8')    const htmlParser = new htmlparser2.Parser({      onopentag(name, attribs = {}) {        if (name !== 'import' &amp;&amp; name !== 'require') {          return\n        }        const { src } = attribs        if (src) {          return\n        }      \tconst wxmlFile = path.resolve(dirName, src)        if (fs.existsSync(wxmlFile)) {\n        \tdeps.push(wxmlFile)\n        }\n      }\n    })\n    htmlParser.write(content)\n    htmlParser.end()    return deps\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u83b7\u53d6 .wxss \u6587\u4ef6\u4f9d\u8d56<\/h3>\n<p>\u6700\u540e wxss \u6587\u4ef6\u5bfc\u5165\u6837\u5f0f\u548c css \u8bed\u6cd5\u4e00\u81f4\uff0c\u4f7f\u7528 @import \u8bed\u53e5\u53ef\u4ee5\u5bfc\u5165\u5916\u8054\u6837\u5f0f\u8868\u3002<\/p>\n<pre>@import \"common.wxss\";\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 postcss \u89e3\u6790 wxss \u6587\u4ef6\uff0c\u7136\u540e\u83b7\u53d6\u5bfc\u5165\u6587\u4ef6\u7684\u5730\u5740\uff0c\u4f46\u662f\u8fd9\u91cc\u6211\u4eec\u5077\u4e2a\u61d2\uff0c\u76f4\u63a5\u901a\u8fc7\u7b80\u5355\u7684\u6b63\u5219\u5339\u914d\u6765\u505a\u3002<\/p>\n<pre>class Depend {  \/\/ ...\n  wxssDeps(file) {    const deps = []    const dirName = path.dirname(file)    const content = fs.readFileSync(file, 'utf-8')    const importRegExp = \/@import\\s*['\"](.+)['\"];*\/g\n    let matched    while ((matched = importRegExp.exec(content)) !== null) {      if (!matched[1]) {        continue\n      }      const wxssFile = path.resolve(dirName, matched[1])      if (fs.existsSync(wxmlFile)) {\n        deps.push(wxssFile)\n      }\n    }    return deps\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>\u5c06\u4f9d\u8d56\u6dfb\u52a0\u5230\u6811\u7ed3\u6784\u4e2d<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u9700\u8981\u4fee\u6539 addToTree \u65b9\u6cd5\u3002<\/p>\n<pre>class Depend {  addToTree(filePath) {    \/\/ \u5982\u679c\u8be5\u6587\u4ef6\u5df2\u7ecf\u6dfb\u52a0\u8fc7\uff0c\u5219\u4e0d\u518d\u6dfb\u52a0\u5230\u6587\u4ef6\u6811\u4e2d\n    if (this.files.has(filePath)) {      return\n    }    const relPath = this.getRelative(filePath)    const names = relPath.split(path.sep)\n    names.forEach((name, idx) =&gt; {      \/\/ ... \u6dfb\u52a0\u5230\u6811\u4e2d\n    })    this.files.add(filePath)    \/\/ ===== \u83b7\u53d6\u6587\u4ef6\u4f9d\u8d56\uff0c\u5e76\u6dfb\u52a0\u5230\u6811\u4e2d =====\n    const deps = this.getDeps(filePath)\n    deps.forEach(dep =&gt; {      this.addToTree(dep)      \n    })\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/c4e2d3ff0ec63e9a7efdd5b6db6fbfcd-5.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe6\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe6\" \/><\/p>\n<h2>\u83b7\u53d6\u5206\u5305\u4f9d\u8d56<\/h2>\n<p>\u719f\u6089\u5c0f\u7a0b\u5e8f\u7684\u540c\u5b66\u80af\u5b9a\u77e5\u9053\uff0c\u5c0f\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u5206\u5305\u673a\u5236\u3002\u4f7f\u7528\u5206\u5305\u540e\uff0c\u5206\u5305\u5185\u7684\u6587\u4ef6\u4f1a\u88ab\u6253\u5305\u6210\u4e00\u4e2a\u5355\u72ec\u7684\u5305\uff0c\u5728\u7528\u5230\u7684\u65f6\u5019\u624d\u4f1a\u52a0\u8f7d\uff0c\u800c\u5176\u4ed6\u7684\u6587\u4ef6\u5219\u4f1a\u653e\u5728\u4e3b\u5305\uff0c\u5c0f\u7a0b\u5e8f\u6253\u5f00\u7684\u65f6\u5019\u5c31\u4f1a\u52a0\u8f7d\u3002subpackages \u4e2d\uff0c\u6bcf\u4e2a\u5206\u5305\u7684\u914d\u7f6e\u6709\u4ee5\u4e0b\u51e0\u9879\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b57\u6bb5<\/th>\n<th>\u7c7b\u578b<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>root<\/td>\n<td>String<\/td>\n<td>\u5206\u5305\u6839\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td>name<\/td>\n<td>String<\/td>\n<td>\u5206\u5305\u522b\u540d\uff0c\u5206\u5305\u9884\u4e0b\u8f7d\u65f6\u53ef\u4ee5\u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td>pages<\/td>\n<td>StringArray<\/td>\n<td>\u5206\u5305\u9875\u9762\u8def\u5f84\uff0c\u76f8\u5bf9\u4e0e\u5206\u5305\u6839\u76ee\u5f55<\/td>\n<\/tr>\n<tr>\n<td>independent<\/td>\n<td>Boolean<\/td>\n<td>\u5206\u5305\u662f\u5426\u662f\u72ec\u7acb\u5206\u5305<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u4ee5\u6211\u4eec\u5728\u8fd0\u884c\u7684\u65f6\u5019\uff0c\u9664\u4e86\u8981\u62ff\u5230 pages \u4e0b\u7684\u6240\u6709\u9875\u9762\uff0c\u8fd8\u9700\u62ff\u5230 subpackages \u4e2d\u6240\u6709\u7684\u9875\u9762\u3002\u7531\u4e8e\u4e4b\u524d\u53ea\u5173\u5fc3\u4e3b\u5305\u7684\u5185\u5bb9\uff0cthis.tree \u4e0b\u9762\u53ea\u6709\u4e00\u9897\u6587\u4ef6\u6811\uff0c\u73b0\u5728\u6211\u4eec\u9700\u8981\u5728 this.tree \u4e0b\u6302\u8f7d\u591a\u9897\u6587\u4ef6\u6811\uff0c\u6211\u4eec\u9700\u8981\u5148\u4e3a\u4e3b\u5305\u521b\u5efa\u4e00\u4e2a\u5355\u72ec\u7684\u6587\u4ef6\u6811\uff0c\u7136\u540e\u4e3a\u6bcf\u4e2a\u5206\u5305\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u6811\u3002<\/p>\n<pre>class Depend {  constructor() {    this.tree = {}    this.files = new Set()    this.context = path.join(root, 'miniprogram')\n  }  createTree(pkg) {    this.tree[pkg] = {      size: 0,      children: {}\n    }\n  }  addPage(page, pkg) {    const absPath = this.getAbsolute(page)\n    Extends.forEach(ext =&gt; {      const filePath = this.replaceExt(absPath, ext)      if (fs.existsSync(filePath)) {        this.addToTree(filePath, pkg)\n      }\n    })\n  }  run() {    const appPath = this.getAbsolute('app.json')    const appJson = fs.readJsonSync(appPath)    const { pages, subPackages, subpackages } = appJson    \n    this.createTree('main') \/\/ \u4e3a\u4e3b\u5305\u521b\u5efa\u6587\u4ef6\u6811\n    pages.forEach(page =&gt; {      this.addPage(page, 'main')\n    })    \/\/ \u7531\u4e8e app.json \u4e2d subPackages\u3001subpackages \u90fd\u80fd\u751f\u6548\n    \/\/ \u6240\u4ee5\u6211\u4eec\u4e24\u4e2a\u5c5e\u6027\u90fd\u83b7\u53d6\uff0c\u54ea\u4e2a\u5b58\u5728\u5c31\u7528\u54ea\u4e2a\n    const subPkgs = subPackages || subpackages    \/\/ \u5206\u5305\u5b58\u5728\u7684\u65f6\u5019\u624d\u8fdb\u884c\u904d\u5386\n    subPkgs &amp;&amp; subPkgs.forEach(({ root, pages }) =&gt; {\n      root = root.split('\/').join(path.sep)      this.createTree(root) \/\/ \u4e3a\u5206\u5305\u521b\u5efa\u6587\u4ef6\u6811\n      pages.forEach(page =&gt; {        this.addPage(`${root}${path.sep}${page}`, pkg)\n      })\n    })    \/\/ \u8f93\u51fa\u6587\u4ef6\u6811\n    fs.writeJSONSync('tree.json', this.tree, { spaces: 2 })\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>addToTree \u65b9\u6cd5\u4e5f\u9700\u8981\u8fdb\u884c\u4fee\u6539\uff0c\u6839\u636e\u4f20\u5165\u7684 pkg \u6765\u5224\u65ad\u5c06\u5f53\u524d\u6587\u4ef6\u6dfb\u52a0\u5230\u54ea\u4e2a\u6811\u3002<\/p>\n<pre>class Depend {  addToTree(filePath, pkg = 'main') {    if (this.files.has(filePath)) {      \/\/ \u5982\u679c\u8be5\u6587\u4ef6\u5df2\u7ecf\u6dfb\u52a0\u8fc7\uff0c\u5219\u4e0d\u518d\u6dfb\u52a0\u5230\u6587\u4ef6\u6811\u4e2d\n      return\n    }    let relPath = this.getRelative(filePath)    if (pkg !== 'main' &amp;&amp; relPath.indexOf(pkg) !== 0) {      \/\/ \u5982\u679c\u8be5\u6587\u4ef6\u4e0d\u662f\u4ee5\u5206\u5305\u540d\u5f00\u5934\uff0c\u8bc1\u660e\u8be5\u6587\u4ef6\u4e0d\u5728\u5206\u5305\u5185\uff0c\n      \/\/ \u9700\u8981\u5c06\u6587\u4ef6\u6dfb\u52a0\u5230\u4e3b\u5305\u7684\u6587\u4ef6\u6811\u5185\n      pkg = 'main'\n    }    const tree = this.tree[pkg] \/\/ \u4f9d\u636e pkg \u53d6\u5230\u5bf9\u5e94\u7684\u6811\n    const size = this.getSize(filePath)    const names = relPath.split(path.sep)    const lastIdx = names.length - 1\n\n    tree.size += size    let point = tree.children\n    names.forEach((name, idx) =&gt; {      \/\/ ... \u6dfb\u52a0\u5230\u6811\u4e2d\n    })    this.files.add(filePath)    \/\/ ===== \u83b7\u53d6\u6587\u4ef6\u4f9d\u8d56\uff0c\u5e76\u6dfb\u52a0\u5230\u6811\u4e2d =====\n    const deps = this.getDeps(filePath)\n    deps.forEach(dep =&gt; {      this.addToTree(dep)      \n    })\n  }\n}\u590d\u5236\u4ee3\u7801<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u5982\u679c package\/a \u5206\u5305\u4e0b\u7684\u6587\u4ef6\u4f9d\u8d56\u7684\u6587\u4ef6\u4e0d\u5728 package\/a &nbsp;\u6587\u4ef6\u5939\u4e0b\uff0c\u5219\u8be5\u6587\u4ef6\u9700\u8981\u653e\u5165\u4e3b\u5305\u7684\u6587\u4ef6\u6811\u5185\u3002<\/p>\n<h2>\u901a\u8fc7 EChart \u753b\u56fe<\/h2>\n<p>\u7ecf\u8fc7\u4e0a\u9762\u7684\u6d41\u7a0b\u540e\uff0c\u6700\u7ec8\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u7684\u4e00\u4e2a json \u6587\u4ef6\uff1a<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/c4e2d3ff0ec63e9a7efdd5b6db6fbfcd-6.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe7\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe7\" \/><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5229\u7528 ECharts \u7684\u753b\u56fe\u80fd\u529b\uff0c\u5c06\u8fd9\u4e2a json \u6570\u636e\u4ee5\u56fe\u8868\u7684\u5f62\u5f0f\u5c55\u73b0\u51fa\u6765\u3002\u6211\u4eec\u53ef\u4ee5\u5728 ECharts \u63d0\u4f9b\u7684\u5b9e\u4f8b\u4e2d\u770b\u5230\u4e00\u4e2a Disk Usage \u7684\u6848\u4f8b\uff0c\u5f88\u7b26\u5408\u6211\u4eec\u7684\u9884\u671f\u3002<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/c4e2d3ff0ec63e9a7efdd5b6db6fbfcd-7.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe8\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe8\" \/><\/p>\n<p>ECharts \u7684\u914d\u7f6e\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\uff0c\u6309\u7167\u5b98\u7f51\u7684 demo \u5373\u53ef\uff0c\u6211\u4eec\u9700\u8981\u628a tree. json \u7684\u6570\u636e\u8f6c\u5316\u4e3a ECharts \u9700\u8981\u7684\u683c\u5f0f\u5c31\u884c\u4e86\uff0c\u5b8c\u6574\u7684\u4ee3\u7801\u653e\u5230 codesandbod \u4e86\uff0c\u53bb\u4e0b\u9762\u7684\u7ebf\u4e0a\u5730\u5740\u5c31\u80fd\u770b\u5230\u6548\u679c\u4e86\u3002<\/p>\n<blockquote><p>\n  \u7ebf\u4e0a\u5730\u5740\uff1ahttps:\/\/codesandbox.io\/s\/cold-dawn-kufc9\n<\/p><\/blockquote>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/052\/10653c1dc86030a585a3595cfb31139d-8.png\" style=\"max-width:90%\" title=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe9\" alt=\"\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u63d2\u56fe9\" \/><\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u6bd4\u8f83\u504f\u5b9e\u8df5\uff0c\u6240\u4ee5\u8d34\u4e86\u5f88\u591a\u7684\u4ee3\u7801\uff0c\u53e6\u5916\u672c\u6587\u5bf9\u5404\u4e2a\u6587\u4ef6\u7684\u4f9d\u8d56\u83b7\u53d6\u63d0\u4f9b\u4e86\u4e00\u4e2a\u601d\u8def\uff0c\u867d\u7136\u8fd9\u91cc\u53ea\u662f\u7528\u6587\u4ef6\u6811\u6784\u9020\u4e86\u4e00\u4e2a\u8fd9\u6837\u7684\u4f9d\u8d56\u56fe\u3002<\/p>\n<p>\u5728\u4e1a\u52a1\u5f00\u53d1\u4e2d\uff0c\u5c0f\u7a0b\u5e8f IDE \u6bcf\u6b21\u542f\u52a8\u90fd\u9700\u8981\u8fdb\u884c\u5168\u91cf\u7684\u7f16\u8bd1\uff0c\u5f00\u53d1\u7248\u9884\u89c8\u7684\u65f6\u5019\u4f1a\u7b49\u5f85\u8f83\u957f\u7684\u65f6\u95f4\uff0c\u6211\u4eec\u73b0\u5728\u6709\u6587\u4ef6\u4f9d\u8d56\u5173\u7cfb\u540e\uff0c\u5c31\u53ef\u4ee5\u53ea\u9009\u53d6\u76ee\u524d\u6b63\u5728\u5f00\u53d1\u7684\u9875\u9762\u8fdb\u884c\u6253\u5305\uff0c\u8fd9\u6837\u5c31\u80fd\u5927\u5927\u63d0\u9ad8\u6211\u4eec\u7684\u5f00\u53d1\u6548\u7387\u3002\u5982\u679c\u6709\u5bf9\u8fd9\u90e8\u5206\u5185\u5bb9\u611f\u5174\u8da3\u7684\uff0c\u53ef\u4ee5\u53e6\u5916\u5199\u4e00\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e0b\u5982\u4f55\u5b9e\u73b0\u3002<\/p>\n<blockquote>\n<p><strong>\u76f8\u5173\u514d\u8d39\u5b66\u4e60\u63a8\u8350\uff1a<\/strong><\/p>\n<\/blockquote>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd\u5c0f\u7a0b\u5e8f\u4f9d\u8d56\u5206\u6790\u5b9e\u8df5\u3002 \u7528\u8fc7 webpack \u7684\u540c\u5b66\u80af\u5b9a\u77e5\u9053 webpack-bundle-analyzer \uff0c\u53ef\u4ee5\u7528\u6765\u5206\u6790\u5f53\u524d\u9879\u76ee js \u6587\u4ef6\u7684\u4f9d\u8d56\u5173\u7cfb\u3002 \u56e0\u4e3a\u6700\u8fd1\u4e00\u76f4\u5728\u505a\u5c0f\u7a0b\u5e8f\u4e1a\u52a1\uff0c\u800c\u4e14\u5c0f\u7a0b\u5e8f\u5bf9\u5305\u4f53\u5927\u5c0f\u7279\u522b\u654f\u611f\uff0c\u6240\u4ee5\u5c31\u60f3\u7740\u80fd\u4e0d\u80fd\u505a\u4e00\u4e2a\u7c7b\u4f3c\u7684\u5de5\u5177\uff0c\u7528\u6765\u67e5\u770b\u5f53\u524d\u5c0f\u7a0b\u5e8f\u5404\u4e2a\u4e3b\u5305\u4e0e\u5206\u5305\u4e4b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u3002\u7ecf\u8fc7\u51e0\u5929\u7684\u6298\u817e\u7ec8\u4e8e\u505a\u51fa\u6765\u4e86\uff0c\u6548\u679c\u5982\u4e0b\uff1a \u4eca\u5929\u7684\u6587\u7ae0\u5c31\u5e26\u5927\u5bb6\u6765\u5b9e\u73b0\u8fd9\u4e2a\u5de5\u5177\u3002 \u5c0f\u7a0b\u5e8f\u5165\u53e3 \u5c0f\u7a0b\u5e8f\u7684\u9875\u9762\u901a\u8fc7 app.json \u7684 pages \u53c2\u6570\u5b9a\u4e49\uff0c\u7528\u4e8e\u6307\u5b9a\u5c0f\u7a0b\u5e8f\u7531\u54ea\u4e9b\u9875\u9762\u7ec4\u6210\uff0c\u6bcf\u4e00\u9879\u90fd\u5bf9\u5e94\u4e00\u4e2a\u9875\u9762\u7684\u8def\u5f84\uff08\u542b\u6587\u4ef6\u540d\uff09 \u4fe1\u606f\u3002 pages \u5185\u7684\u6bcf\u4e2a\u9875\u9762\uff0c\u5c0f\u7a0b\u5e8f\u90fd\u4f1a\u53bb\u5bfb\u627e\u5bf9\u5e94\u7684 json, js, wxml, wxss \u56db\u4e2a\u6587\u4ef6\u8fdb\u884c\u5904\u7406\u3002 \u5982\u5f00\u53d1\u76ee\u5f55\u4e3a\uff1a \u251c\u2500\u2500 app.js \u251c\u2500\u2500 app.json \u251c\u2500\u2500 app.wxss \u251c\u2500\u2500 pages \u2502 \u2502\u2500\u2500 index \u2502 \u2502 \u251c\u2500\u2500 index.wxml \u2502 \u2502 \u251c\u2500\u2500 index.js \u2502 \u2502 \u251c\u2500\u2500 index.json \u2502 \u2502 \u2514\u2500\u2500 index.wxss \u2502 \u2514\u2500\u2500 logs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-33699","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=33699"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33699\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}