公司最近開發項目使用的是vue-cli 3.0
版本開發,可是對於vue-cli 3.0
版本一直沒有研究過如何使用,公司使用配置:pug + ts + stylus + eslint;編輯器使用:vscode,使用起來簡直不要太爽。css
默認你已經安裝了nodejs
前端
vue-cli 3.0
1.安裝:vue
npm install -g @vue/cli
-g
: 全局安裝 vue-cli
1.建立vue-app
項目:node
vue create vue-app
2.項目配置:vue-cli
如下是我選擇的配置(能夠直接按數字鍵1,2,3,4進行選擇)typescript
Babel
:將ES6編譯成ES5TypeScript
:JS超集,主要是類型檢查Router
和Vuex
,路由和狀態管理Linter
/ Formatter
:代碼檢查工具CSS Pre-processors
:css預編譯 (稍後會對這裏進行配置)Unit Testing
:單元測試,開發過程當中前端對代碼進行自運行測試Use class-style component syntax? (Y/n) y
是否使用Class風格裝飾器?
即本來是:home = new Vue()
建立vue實例
使用裝飾器後:class home extends Vue{}
npm
Use Babel alongside TypeScript for auto-detected polyfills? (Y/n) y
使用Babel與TypeScript一塊兒用於自動檢測的填充? yesjson
Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) y
路由使用歷史模式? 這種模式充分利用 history.pushState API 來完成 URL 跳轉而無須從新加載頁面babel
使用什麼css預編譯器? 我選擇的 stylus
app
tslint
: typescript格式驗證工具eslint w...
: 只進行報錯提醒; 【選這個】eslint + A...
: 不嚴謹模式;eslint + S...
: 正常模式;eslint + P...
: 嚴格模式;
代碼檢查方式:我選擇保存時檢查

單元測試工具,這裏附上vue單元測試的連接,想了解的小夥伴戳這裏 https://vue-test-utils.vuejs.org/zh/
vue-cli 通常來說是將全部的依賴目錄放在package.json文件裏
Save this as a preset for future projects? (y/N) n
是否在之後的項目中使用以上配置?不
下載依賴的工具:使用 yarn,速度快。
到此爲止,安裝就完成了,能夠等待安裝成功。
1.vscode
的eslint
配置,使代碼可以在ctrl
+s
的時候自動格式化:
在vue-app
目錄縣新建文件夾.vscode
文件,再在.vscode
目錄下新建settings.json
,文件內容以下:
tips:此配置包含了.vue
文件.styl
文件typescript
的代碼縮進
{ "prettier.printWidth": 160, "prettier.tabWidth": 2, "prettier.semi": false, "prettier.singleQuote": true, "prettier.disableLanguages": [], "editor.tabSize": 2, "[vue]": { "editor.formatOnSave": true }, "[typescript]": { "editor.formatOnSave": true, }, "[stylus]": { "editor.formatOnSave": true, }, "stylusSupremacy.insertColons": false, "stylusSupremacy.insertSemicolons": false, "stylusSupremacy.insertBraces": false, "languageStylus.useSeparator": false, }
vscode
在讀取到vue-app
項目是,回去查找.vscode
下的settings.json
配置並應用。必須禁用插件:eslint
2.使用pug
yarn add pug pug-plain-loader --dev
yarn
安裝 pug
和 pug-plain-loader
;(沒有yarn
的自行百度安裝--dev
:安裝到開發環境App.vue
文件,將文件修改成下面這樣既可。<template lang="pug"> #app #nav router-link(to="/") Home router-link(to="/about") About router-view </div> </template>
0.其餘一些eslint配置均可以在packge.json
文件中的eslintConfig
下的rules
下配置
1.console.log(1)
報錯:
找到packge.json
文件中的eslintConfig
下的rules
:
"no-console": "off"