vue配置項
配置相對路徑
-
webpack構(gòu)建
在build/webpack.base.conf里找到如下 resolve: { extensions: ['.js', '.vue', '.json'],//取消后綴 引入文件路徑就不用加文件后綴了 alias: { 'vue$': 'vue/dist/vue.esm.js', //引入vue '@': resolve('src'), 'asd': resolve('src/components/children'), //自己新建 要從src開始寫文件路徑 } },
- vue cl3
在根目錄下添加'vue.config.js'(有的話就不需要添加醉旦,直接打開就行)
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
lintOnSave: true,
chainWebpack: config => {
config.resolve.alias
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('components', resolve('src/components'))
.set('layout', resolve('src/layout'))
}
}
配置啟動端口和啟動方式
-
webpack構(gòu)建
在build/webpack.config.conf里找到如下 module.exports = { cache: false,// 緩存生成的 webpack 模塊和 chunk,來改善構(gòu)建速度 關(guān)閉緩存或者配置成 /** ** webpack 配置中設(shè)置 cache.buildDependencies.config: [__filename] 來獲取最新配置以及所有依賴項糜值。 ** cache: { ** buildDependencies: { ** This makes all dependencies of this file - build dependencies ** config: [__filename], //默認(rèn)情況下 webpack 與 loader 是構(gòu)建依賴。 ** }, ** }, */ devServer: { compress: true,// 開啟靜態(tài)文件壓縮 gzip compression host:'0.0.0.0',// 默認(rèn)配置 可以從外部打開 // host: '192.168.0.104', inline: true, // 默認(rèn)情況下冯乘,應(yīng)用程序?qū)⒂?inline 模式恕洲,在 bundle中插入腳本以進行實時重新加載来涨,并且構(gòu)建消息將出現(xiàn)在瀏覽器控制臺中 port: 8090,//打開端口 lazy: true,//“懶惰模式(lazy mode)” :服務(wù)器僅在收到請求時才編譯捆綁軟件。也就是 webpack 將不會監(jiān)視任何文件更改启盛。 proxy:: { '/api': { target: 'http://localhost:3000', // 啟用代理在 localhost:3000 上 changeOrigin: true, //代理保留主機頭的來源蹦掐,changeOrigin 設(shè)置為 true 以覆蓋此行為 }, }, open: true, // 設(shè)置為 true 以打開默認(rèn)瀏覽器 /** ** open: 'Chrome', 提供要使用的瀏覽器名稱 ** 瀏覽器應(yīng)用程序名稱取決于平臺。 不要在可重用模塊中對其進行硬編碼僵闯。 ** 例如卧抗,'Chrome' 在 macOS 上是 'Google Chrome' ,在 Linux 上是 'Google Chrome' 在 Windows 上是 'Chrome' */ colors: true, }, },
-
vue cl3
在根目錄下添加'vue.config.js'(有的話就不需要添加鳖粟,直接打開就行) module.exports = { devServer:{ port:3333, // 啟動端口 open:true // 啟動后是否自動打開網(wǎng)頁 } }