vue-cli4搭建項目沒有vue.config.js需在根目錄手動添加,官網給出拉取cli2模板。
npm install -g @vue/cli-init
// `vue init` 的運行效果將會跟 `[email protected]` 相同
vue init webpack my-project
手動創建 vue.config.js複製粘貼,保存到根目錄。
module.exports = {
//baseUrl: process.env.NODE_ENV === 'production' ? '/online/' : '/',
// outputDir: 在npm run build時 生成文件的目錄 type:string, default:'dist'
// outputDir: 'dist',
// pages:{ type:Object,Default:undfind }
devServer: {
port: 8090, // 端口號
host: 'localhost',
https: false, // https:{type:Boolean}
open: true, //配置自動啓動瀏覽器
// proxy: 'http://localhost:4000' // 配置跨域處理,只有一個代理
proxy: {
'/api': {
target: '<url>',
ws: true,
changeOrigin: true
},
'/foo': {
target: '<other_url>'
}
}, // 配置多個代理
}
}
vue-cli4
運行 sudo npm install -g @vue/cli //安裝
sudo npm uninstall -g @vue/cli //卸載
vue create demo // 創建項目
npm run serve // 項目啓動
vue-cli2
運行:sudo npm install -g vue-cli //安裝
sudo npm uninstall -g vue-cli //卸載