vue-cli 3.x 修改dist路徑和在本地查看方法

打包文件路徑問題

須要在項目的根目錄添加一個vue.config.js。在這個文件中,咱們能夠進行一些個性化定製。css

module.exports = {
 // 基本路徑
 baseUrl: './',
 // 輸出文件目錄
 outputDir: 'dist',
 // 生產環境是否生成 sourceMap 文件
 productionSourceMap: false,
 // 服務器端口號
 devServer: {
   port: 1234
  },
}

而後運行yarn build 操做便可html

詳細配置vue

module.exports = {
     // 基本路徑
     baseUrl: '/',
     // 輸出文件目錄
     outputDir: 'dist',
     // eslint-loader 是否在保存的時候檢查
     lintOnSave: true,
     // use the full build with in-browser compiler?
     // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
     compiler: false,
     // webpack配置
     // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
     chainWebpack: () => {},
     configureWebpack: () => {},
     // vue-loader 配置項
     // https://vue-loader.vuejs.org/en/options.html
     vueLoader: {},
     // 生產環境是否生成 sourceMap 文件
     productionSourceMap: true,
     // css相關配置
     css: {
      // 是否使用css分離插件 ExtractTextPlugin
      extract: true,
      // 開啓 CSS source maps?
      sourceMap: false,
      // css預設器配置項
      loaderOptions: {},
         // 啓用 CSS modules for all css / pre-processor files.
         modules: false
       },
     // use thread-loader for babel & TS in production build
     // enabled by default if the machine has more than 1 cores
     parallel: require('os').cpus().length > 1,
    // 是否啓用dll
    // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
    dll: false,
    // PWA 插件相關配置
    // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
   pwa: {},
    // webpack-dev-server 相關配置
    devServer: {
   open: process.platform === 'darwin',
      host: '0.0.0.0',
      port: 8080,
      https: false,
      hotOnly: false,
      proxy: null, // 設置代理
      before: app => {}
     },
     // 第三方插件配置
   pluginOptions: {
      // ...
     }
}

本地打開運行方法

改好以後就能夠直接在本地打開index.html了,但一片空白也說明了dist 目錄須要啓動一個 HTTP 服務器來訪問,因此以 file:// 協議直接打開 dist/index.html 是不會工做的。
不知道爲何我運行下面命令不起做用,有空再研究下吧webpack

npm install -g serve
# -s 參數的意思是將其架設在 Single-Page Application 模式下
# 這個模式會處理即將提到的路由問題
serve -s dist

就在網上查看了一下,我用了其中一種方法(參考):git

執行下面命令:github

1.打開終端,全局安裝web

npm install http-server -g

2.cd命令進入dist文件,執行:vue-cli

http-server

直接打開上面的網址訪問就能夠了。npm

相關文章
相關標籤/搜索