部分依賴包的版本:vue
1 "dependencies": { 2 "vue": "^2.3.3", 3 "vue-router": "^2.3.1" 4 }, 5 "devDependencies": { 6 "eslint-loader": "^1.7.1", 7 "stylus": "^0.54.5", 8 "stylus-loader": "^3.0.1", 9 "url-loader": "^0.5.8", 10 "vue-loader": "^12.1.0", 11 "vue-style-loader": "^3.0.1", 12 "vue-template-compiler": "^2.3.3", 13 "webpack": "^2.6.1", 14 }
1.使用stylus須要先再package.json中配置'stylus'和'stylus-loader',並執行'npm install stylus-loader stylus --save-dev'命令。webpack
1.1將全部styl文件依賴到一個主文件index.stly,而後在main.js裏依賴主文件web
//index.styl文件,經過@import將其餘styl文件注入依賴 @import "base" @import "mixin" @import "icon"
2.在webpack.base.conf文件中配置別名以及擴展名vue-router
注意:‘__dirname’是兩個下劃線!npm
resolve: { extensions: ['.js', '.vue', '.json', '.styl'], alias: { 'vue$': 'vue/dist/vue.esm.js', '@': resolve('src'), 'src': path.resolve(__dirname, '../src'), 'common': path.resolve(__dirname, '../src/common'), 'components': path.resolve(__dirname, '../src/components') } }
配置好別名和擴展名後,main.js就能夠這樣寫:json
import Vue from 'vue'; import App from './App'; import Router from 'vue-router'; //components前面能夠加上'@/',也能夠省略不寫 //若是沒有別名,就要寫成「import goods from '../components/goods/goods';「 import goods from 'components/goods/goods'; import seller from 'components/seller/seller'; import ratings from 'components/ratings/ratings'; import '@/common/stylus/index';