vue-cli 2とvue-cli 3

34440 ワード

Vue
vue-cli2 与 vue-cli3_第1张图片チェックシャツが似合いますよ
インストール
Node環境、http://nodejs.cn/download/
vue-cli2
npm install -g vue-cli
vue -V

vue init webpack my-project //       

vue-cli2 与 vue-cli3_第2张图片
Project name:プロジェクト名は、必要でなければそのまま車に戻ります.注意:ここでは、大文字は使用できません.Project description:プロジェクトの説明、直接車に戻るAuthor:著者vue build構築方式(一応説明)2つの選択(上下矢印選択、車に戻る選択)1.Runtime+Compiler:recommended for most users(運転+コンパイル:多くのユーザーに推奨される)2.Runtime-only:about 6KB lighter min+gzip,but templates (or any Vue-specific HTML) are ONLY allowed in .vue file-render functions are required elsewhereほとんどのユーザーに適したinstall vue-router?vueのルーティングプラグインをインストールするかどうかは、yを選択する必要があります.そうでなければn(以下、この方法に従う)UseESLint to lint your code?ESLintを使用してコードを検出しますか?(ESLintは文法規則とコードスタイルの検査ツールで、文法が正しく、スタイルが統一されたコードを書くことを保証することができます.)Pick an ESLint preset:分岐スタイルを選択するオプションは3つあります1.standard(https://github.com/feross/standard)jsのスタンダードスタイル2.Airbnb(https://github.com/airbnb/javascript)JavaScriptの最も合理的な方法、このgithubアドレスはJavaScriptの最も合理的な方法と言います3.none(configure it yourself)自分で設定します.ユニットテストをインストールしますか(詳しくは説明しません)Pick a test runnerユニットテストランナを選択します.1.Jest(JestはFacebookで公開されたオープンソース、JasmineベースのJavaScriptユニットテストフレームワーク)2.Karma and Mocha 3.none Setup e 2 e tests with Nightwatch(Y/n)が3つありますか?E 2 EテストフレームワークNightWatch(E 2 E、つまりEnd To End、いわゆる「ユーザーリアルシーン」をインストールするかどうか.)Should we run‘npm install’for you after the project has been created?(例:プロジェクト作成後に「npm install」を実行しますか?ここでパッケージ管理ツールを選択)オプションは3つyes、use npm(npmを使用)yes、use yarn(yarnを使用)no、I will handle that myself(自分で操作)車に戻ってインストールが終わるまで待つと、次のコマンドラインが表示されます
在这里插入图片描述
vue-cli2 与 vue-cli3_第3张图片コマンドラインはpackageを起動する.json scriptでの表示と構成vue-cli2 与 vue-cli3_第4张图片
開始
npm run dev

梱包する
npm run build

プロファイルを変更する場合は対応する場所eg:vue-cliで生成した開発環境を用いてconfig/indexを直接変更する.jsファイルは、proxytable:{}の中を以下のように配置し、後のapiはtargetを歩きます.
proxyTable: {
  '/api': {
    target: 'http://xxxxx.com',
    changeOrigin: true,
    pathRewrite: {
      '^/api': '/api'
    }
  }
}

vue-cli3
npm install -g @vue/cli 

Vue-Cli 2と3は両立できません.少なくとも同時にインストールできません.1つしか残っていません.
現在、足場はvue-cli 3になっていますが、一部の古いプロジェクトはvue-cli 2に依存しています.特にiniはファイルを作成し、また使いたいと思っています.どうすればいいですかvue-cli2 与 vue-cli3_第5张图片
    Vue-Cli 2:npm uninstall vue-cli -g yarn global remove vue-cli

  Vue-Cli 3:npm install -g @vue/cli yarn global add @vue/cli

     :npm install -g @vue/cli-init yarn global add @vue/cli-init

vue create my-project


vue-cli2 与 vue-cli3_第6张图片比較すると、ファイルは簡単明瞭で、これはきれいなプロジェクト構造で、その後、ルートとvuexを自分でインストールすることができます.
npm install vuex -s
npm install vue-router -s

次のように操作することもできます.
vue ui

vue-cli2 与 vue-cli3_第7张图片必要に応じてプロジェクトを新規作成し、自分で選択またはデフォルトを設定できます.
プロジェクト構成では、同じレベルのファイルの下にvueを新規作成します.config.js、よく使うのはpublicPath、エージェント、そしてプラグインです.具体的には公式サイトを見ることができます.https://cli.vuejs.org/
module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',

  outputDir: 'dist',

  assetsDir: 'static',

  filenameHashing: true,

  // When building in multi-pages mode, the webpack config will contain different plugins
  // (there will be multiple instances of html-webpack-plugin and preload-webpack-plugin).
  // Make sure to run vue inspect if you are trying to modify the options for those plugins.
  pages: {
    index: {
      // entry for the pages
      entry: 'src/pages/index/index.js',
      // the source template
      template: 'src/pages/index/index.html',
      // output as dist/index.html
      filename: 'index.html',
      // when using title option,
      // template title tag needs to be </span>
      title<span class="token punctuation">:</span> <span class="token string">'  '</span><span class="token punctuation">,</span>
      <span class="token comment">// chunks to include on this pages, by default includes</span>
      <span class="token comment">// extracted common chunks and vendor chunks.</span>
      chunks<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">'chunk-vendors'</span><span class="token punctuation">,</span> <span class="token string">'chunk-common'</span><span class="token punctuation">,</span> <span class="token string">'index'</span><span class="token punctuation">]</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// when using the entry-only string format,</span>
    <span class="token comment">// template is inferred to be `public/subpage.html`</span>
    <span class="token comment">// and falls back to `public/index.html` if not found.</span>
    <span class="token comment">// Output filename is inferred to be `subpage.html`.</span>
    <span class="token comment">// subpage: ''</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// eslint-loader           </span>
  lintOnSave<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>

  <span class="token comment">//              Vue     </span>
  runtimeCompiler<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

  <span class="token comment">//       babel-loader           node_modules</span>
  transpileDependencies<span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span>

  <span class="token comment">//      sourceMap</span>
  productionSourceMap<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

  <span class="token comment">// cors    https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors</span>
  <span class="token comment">// corsUseCredentials: false,</span>
  <span class="token comment">// webpack   ,          ,         </span>
  <span class="token comment">// https://cli.vuejs.org/guide/webpack.html#simple-configuration</span>
  configureWebpack<span class="token punctuation">:</span> <span class="token punctuation">(</span>config<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// webpack    API,        webapck   </span>
  <span class="token comment">// https://github.com/mozilla-neutrino/webpack-chain</span>
  chainWebpack<span class="token punctuation">:</span> <span class="token punctuation">(</span>config<span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token comment">//       ,     chunks,             JS / CSS</span>
    config<span class="token punctuation">.</span>optimization
      <span class="token punctuation">.</span><span class="token function">splitChunks</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
        cacheGroups<span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token comment">// 'src/lib'          ,    eslint   </span>
    config<span class="token punctuation">.</span>module
      <span class="token punctuation">.</span><span class="token function">rule</span><span class="token punctuation">(</span><span class="token string">'eslint'</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span>exclude
      <span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token string">'/Users/maybexia/Downloads/FE/community_built-in/src/lib'</span><span class="token punctuation">)</span>
      <span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">//     chainWebpack    css loader    </span>
  css<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token comment">//        foo.module.css   </span>
    modules<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

    <span class="token comment">//      css      ExtractTextPlugin,          ,    <style>       html    </span>
    extract<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>

    <span class="token comment">//         ,false        </span>
    sourceMap<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

    <span class="token comment">// css      </span>
    loaderOptions<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      css<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token comment">// options here will be passed to css-loader</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>

      postcss<span class="token punctuation">:</span> <span class="token punctuation">{</span>
        <span class="token comment">// options here will be passed to postcss-loader</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">// All options for webpack-dev-server are supported</span>
  <span class="token comment">// https://webpack.js.org/configuration/dev-server/</span>
  devServer<span class="token punctuation">:</span> <span class="token punctuation">{</span>
    open<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>

    host<span class="token punctuation">:</span> <span class="token string">'127.0.0.1'</span><span class="token punctuation">,</span>

    port<span class="token punctuation">:</span> <span class="token number">3000</span><span class="token punctuation">,</span>

    https<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

    hotOnly<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>

    proxy<span class="token punctuation">:</span> <span class="token keyword">null</span><span class="token punctuation">,</span>
	
	<span class="token comment">// proxy:"http://xxxx.com",</span>
    proxy<span class="token punctuation">:</span> <span class="token punctuation">{</span>
      <span class="token string">'/api'</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
        target<span class="token punctuation">:</span> <span class="token string">'http://xxxxx.com/'</span><span class="token punctuation">,</span>
        ws<span class="token punctuation">:</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
        changeOrigin<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">//      </span>
        pathRewrite<span class="token punctuation">:</span> <span class="token punctuation">{</span>
          <span class="token string">'^/'</span><span class="token punctuation">:</span> <span class="token string">'/'</span><span class="token punctuation">,</span> <span class="token comment">//  </span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token comment">//       </span>


    before<span class="token punctuation">:</span> app <span class="token operator">=></span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token comment">//            babel   </span>
  parallel<span class="token punctuation">:</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'os'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">cpus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>length <span class="token operator">></span> <span class="token number">1</span><span class="token punctuation">,</span>

  <span class="token comment">// https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa</span>
  pwa<span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>

  <span class="token comment">//        </span>
  pluginOptions<span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

</code></pre> 
  <p>package.json<br> <a href="https://img.md5.com/image/info8/de9c1d12b20f465e85cc7a9251cb4028.jpg" target="_blank"><img src="https://img.md5.com/image/info8/de9c1d12b20f465e85cc7a9251cb4028.jpg" alt="vue-cli2   vue-cli3_ 8   " width="649" height="669" style="border:1px solid black;"></a><br>   </p> 
  <pre><code class="prism language-shell"><span class="token function">npm</span> run serve
</code></pre> 
  <p>  </p> 
  <pre><code class="prism language-shell"><span class="token function">npm</span> run build
</code></pre> 
 </div> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC WAP    -->
                    <div id="SOHUCS" sid="1277471428244946944"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!--    -         -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!--    -  1       -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!--    -  2       -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!--    -  3       -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">       </h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                                <li><a href="/article/71.htm"
                                       title="Linux Initrd  " target="_blank">Linux Initrd  </a>
                                    <span class="text-muted">   </span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                                </li>
                                <li><a href="/article/198.htm"
                                       title="maven        " target="_blank">maven        </a>
                                    <span class="text-muted">bitcarter</span>
<a class="tag" taget="_blank" href="/search/maven/1.htm">maven</a>
                                </li>
                                <li><a href="/article/325.htm"
                                       title="XSD XML      " target="_blank">XSD XML      </a>
                                    <span class="text-muted">darrenzhu</span>
<a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/xsd/1.htm">xsd</a><a class="tag" taget="_blank" href="/search/schema/1.htm">schema</a><a class="tag" taget="_blank" href="/search/namespace/1.htm">namespace</a><a class="tag" taget="_blank" href="/search/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4/1.htm">    </a>
                                </li>
                                <li><a href="/article/452.htm"
                                       title="Java      " target="_blank">Java      </a>
                                    <span class="text-muted">   </span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E7%AE%97%E6%B3%95/1.htm">  </a><a class="tag" taget="_blank" href="/search/%E7%B4%A0%E6%95%B0/1.htm">  </a>
                                </li>
                                <li><a href="/article/579.htm"
                                       title="java     " target="_blank">java     </a>
                                    <span class="text-muted">g21121</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                                </li>
                                <li><a href="/article/706.htm"
                                       title="Linux Mysql    " target="_blank">Linux Mysql    </a>
                                    <span class="text-muted">510888780</span>
<a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a>
                                </li>
                                <li><a href="/article/833.htm"
                                       title="32  64     " target="_blank">32  64     </a>
                                    <span class="text-muted">      </span>
<a class="tag" taget="_blank" href="/search/32%E4%BD%8D%E5%92%8C64%E4%BD%8D%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/1.htm">32  64     </a>
                                </li>
                                <li><a href="/article/960.htm"
                                       title="  spring    10-   _Spring  " target="_blank">  spring    10-   _Spring  </a>
                                    <span class="text-muted">aijuans</span>
<a class="tag" taget="_blank" href="/search/Spring+3/1.htm">Spring 3</a>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>     :</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">  </a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">  </a> -
            <a target="_blank" href="/custom/about.htm">    </a> -
            <a target="_blank" href="/search/Java/1.htm">    </a> -
            <a target="_blank" href="/sitemap.xml">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">    </a>
        </div>
        <div class="copyright">     IT    CopyRight © 2000-2050 IT    IT610.com , All Rights Reserved.
            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank"> ICP 09083238 </a><br>
        </div>
    </div>
</footer>
<!--      -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html></style></span></code></pre></div></div></div></div>