optimize.html 15.2 KB
Newer Older
EvanOne(文一)'s avatar
EvanOne(文一) 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>优化建议 | hexo-theme-stun</title>
    <meta name="generator" content="VuePress 1.5.2">
    <link rel="icon" href="/hexo-theme-stun/icons/favicon-32x32.png">
    <meta name="description" content="一个漂亮、简洁的 Hexo 主题">
    <link rel="preload" href="/hexo-theme-stun/assets/css/0.styles.bed02c6c.css" as="style"><link rel="preload" href="/hexo-theme-stun/assets/js/app.b850f147.js" as="script"><link rel="preload" href="/hexo-theme-stun/assets/js/2.883641a6.js" as="script"><link rel="preload" href="/hexo-theme-stun/assets/js/16.aefc9e47.js" as="script"><link rel="preload" href="/hexo-theme-stun/assets/js/3.67dc95e3.js" as="script"><link rel="prefetch" href="/hexo-theme-stun/assets/js/10.b83ac2ab.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/11.5d746985.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/12.7359c5ec.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/13.e62248d6.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/14.68c5f93f.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/15.88a42515.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/17.e1988749.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/18.5cde9d58.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/19.a9abcb29.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/20.ecbadd78.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/4.d9ad600e.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/5.685d6db4.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/6.9f577310.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/7.47a12772.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/8.aec2064e.js"><link rel="prefetch" href="/hexo-theme-stun/assets/js/9.b0c5ecc0.js">
    <link rel="stylesheet" href="/hexo-theme-stun/assets/css/0.styles.bed02c6c.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/hexo-theme-stun/zh-CN/" class="home-link router-link-active"><img src="/hexo-theme-stun/icons/favicon-192x192.png" alt="hexo-theme-stun" class="logo"> <span class="site-name can-hide">hexo-theme-stun</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="配置指南" class="dropdown-title"><span class="title">配置指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/guide/quick-start.html" class="nav-link">
  快速开始
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/guide/primary.html" class="nav-link">
  新手上路
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="高级设置" class="dropdown-title"><span class="title">高级设置</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/advanced.html" class="nav-link">
  新手进阶
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/third-part.html" class="nav-link">
  第三方支持
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/assist.html" class="nav-link">
  辅助功能
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/optimize.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  优化建议
</a></li></ul></div></div><div class="nav-item"><a href="/hexo-theme-stun/zh-CN/contribute/contribute.html" class="nav-link">
  参与贡献
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">选择语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/advanced/optimize.html" class="nav-link">
  English
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/optimize.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  简体中文
</a></li></ul></div></div> <a href="https://github.com/liuyib/hexo-theme-stun" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="配置指南" class="dropdown-title"><span class="title">配置指南</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/guide/quick-start.html" class="nav-link">
  快速开始
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/guide/primary.html" class="nav-link">
  新手上路
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="高级设置" class="dropdown-title"><span class="title">高级设置</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/advanced.html" class="nav-link">
  新手进阶
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/third-part.html" class="nav-link">
  第三方支持
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/assist.html" class="nav-link">
  辅助功能
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/optimize.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  优化建议
</a></li></ul></div></div><div class="nav-item"><a href="/hexo-theme-stun/zh-CN/contribute/contribute.html" class="nav-link">
  参与贡献
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Select language" class="dropdown-title"><span class="title">选择语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/advanced/optimize.html" class="nav-link">
  English
</a></li><li class="dropdown-item"><!----> <a href="/hexo-theme-stun/zh-CN/advanced/optimize.html" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  简体中文
</a></li></ul></div></div> <a href="https://github.com/liuyib/hexo-theme-stun" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>配置指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/hexo-theme-stun/zh-CN/guide/quick-start.html" class="sidebar-link">快速开始</a></li><li><a href="/hexo-theme-stun/zh-CN/guide/primary.html" class="sidebar-link">新手上路</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>高级设置</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/hexo-theme-stun/zh-CN/advanced/advanced.html" class="sidebar-link">新手进阶</a></li><li><a href="/hexo-theme-stun/zh-CN/advanced/third-part.html" class="sidebar-link">第三方支持</a></li><li><a href="/hexo-theme-stun/zh-CN/advanced/assist.html" class="sidebar-link">辅助功能</a></li><li><a href="/hexo-theme-stun/zh-CN/advanced/optimize.html" aria-current="page" class="active sidebar-link">优化建议</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/hexo-theme-stun/zh-CN/advanced/optimize.html#打包、压缩资源文件" class="sidebar-link">打包、压缩资源文件</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>参与贡献</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/hexo-theme-stun/zh-CN/contribute/contribute.html" class="sidebar-link">贡献准则</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="优化建议"><a href="#优化建议" class="header-anchor">#</a> 优化建议</h1> <h2 id="打包、压缩资源文件"><a href="#打包、压缩资源文件" class="header-anchor">#</a> 打包、压缩资源文件 <span class="badge warning" style="vertical-align:top;" data-v-15b7b770>Disrelated</span></h2> <div class="custom-block danger"><p class="custom-block-title">WARNING</p> <p>由于我在使用过程中,发现了该插件的很多问题,例如:<a href="https://github.com/chenzhutian/hexo-all-minifier/issues/93" target="_blank" rel="noopener noreferrer">#93<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a>,所以暂时不再推荐使用!</p></div> <p>Stun 主题的源码中,<code>HTML</code>, <code>CSS</code>, <code>JavaScript</code>, <code>图片</code> 等资源文件是没有打包压缩的。绝大部分的 Hexo 主题也是如此。庆幸的是,可以找到相关的插件来解决这一问题。</p> <p>这里可以使用 <a href="https://github.com/chenzhutian/hexo-all-minifier" target="_blank" rel="noopener noreferrer">hexo-all-minifier<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a> 插件,它集成了 <code>html-minifier</code>, <code>clean-css</code>, <code>uglify</code><code>imagemin</code>,只需安装和简单的配置即可使用。</p> <ul><li><p>安装</p> <p>在 Hexo 根目录下执行指令。</p> <blockquote><p>一定要在 Git Bash 中执行,在 Window 的 PowerShell 或 CMD 中执行可能会失败。建议养成在 Git Bash 中执行 npm 指令的好习惯!</p></blockquote> <div class="language-bash extra-class"><pre class="language-bash"><code>$ <span class="token function">npm</span> <span class="token function">install</span> hexo-all-minifier --save
</code></pre></div><p>如果是 Mac 用户,你还需要执行下面的指令。</p> <div class="language-bash extra-class"><pre class="language-bash"><code>$ brew <span class="token function">install</span> libtool automake autoconf nasm
</code></pre></div></li> <li><p>使用</p> <p>在 Hexo 根目录下的 <code>_config.yml</code> 文件中,添加以下字段即可使用。</p> <div class="language-yaml extra-class"><pre class="language-yaml"><code><span class="token key atrule">all_minifier</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
</code></pre></div></li></ul> <p>如果你使用插件时<strong>遇到了问题</strong> 或者 想进行<strong>更详细的设置</strong>,请查看插件的<a href="https://github.com/chenzhutian/hexo-all-minifier/blob/master/README.md" target="_blank" rel="noopener noreferrer">文档<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <blockquote><p><s>安装这个插件后,不管使用哪一个主题,都可以生效,所以强烈推荐使用。</s></p></blockquote></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/liuyib/hexo-theme-stun/edit/master/docs/zh-CN/advanced/optimize.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2020/5/5 下午1:34:17</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">

      <a href="/hexo-theme-stun/zh-CN/advanced/assist.html" class="prev">
        辅助功能
      </a></span> <span class="next"><a href="/hexo-theme-stun/zh-CN/contribute/contribute.html">
        贡献准则
      </a>

    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/hexo-theme-stun/assets/js/app.b850f147.js" defer></script><script src="/hexo-theme-stun/assets/js/2.883641a6.js" defer></script><script src="/hexo-theme-stun/assets/js/16.aefc9e47.js" defer></script><script src="/hexo-theme-stun/assets/js/3.67dc95e3.js" defer></script>
  </body>
</html>