打包vue项目

把router文件夹中的index.js中的history改为hash

const router = new VueRouter({
  mode: 'history',//改为hash
  base: process.env.BASE_URL,
  routes
})

把vue.config.js中的publicPath和assetsDir路径都改为“./”

module.exports = {
    runtimeCompiler: true,
    publicPath: './', // 设置打包文件相对路径
    assetsDir:'./',
    devServer: {
      // open: process.platform === 'darwin',
      // host: 'localhost',
      port: 8071,
      // open: true, //配置自动启动浏览器
      proxy: {
        '/api': {
          target: 'https://cnodejs.org/api/v1/', //对应自己的接口
          changeOrigin: true,
          ws: true,
          pathRewrite: {
            '^/api': ''
          }
        }
      }
     },
  }

最后在命令窗口输入  npm run build 

到这里,就打包完成啦

你可能感兴趣的:(vue)