解决package.json文件添加--open,“scripts“: { “serve“: “vue-cli-service serve --open“,}浏览器显示无法打开此网站

在vue.config.js里面添加以下代码即可成功打开网页

const { defineConfig } = require('@vue/cli-service')

const path = require('path')

module.exports = defineConfig({

  // 部署应用包时的基本 URL,用法和 webpack 本身的 output.publicPath 一致

  publicPath: '/qw_manage/',  

  // 输出文件目录

  outputDir: 'dist',  

  // eslint-loader 是否在保存的时候检查

  lintOnSave: false,  

  // 是否使用包含运行时编译器的 Vue 构建版本

  runtimeCompiler: false,  

  // 生产环境是否生成 sourceMap 文件

  productionSourceMap: false,  

  // 生成的 HTML 中的 <link rel="stylesheet"> 和 <script> 标签上启用 Subresource Integrity (SRI)

  integrity: false,

  transpileDependencies: true,

  // webpack相关配置

  chainWebpack: (config) => {

    config.resolve.alias

      .set('vue$', 'vue/dist/vue.esm.js')

      .set('@', path.resolve(__dirname, './src'))

  },

  configureWebpack: (config) => {    

    if (process.env.NODE_ENV === 'production') {      

      // 生产环境

      config.mode = 'production'

    } else {      

      // 开发环境

      config.mode = 'development'

    }

  },  

  // css相关配置

  css: {    

    // 是否分离css(插件ExtractTextPlugin)

    extract: true,    

    // 是否开启 CSS source maps

    sourceMap: false,  

  },  

  // 是否使用 thread-loader

  parallel: require('os').cpus().length > 1,

  // PWA 插件相关配置

  pwa: {},

  // webpack-dev-server 相关配置

  devServer: {

    open: true,

    host: '127.0.0.1',

    port: 8080,

    https: false,

    hot: 'only',  

    // http 代理配置

    proxy: {

      '/api': {

        target: 'http://192.168.1.31:7090',// 后端接口

        changeOrigin: true, // 是否跨域

        pathRewrite: {

          '/api': ''

        }

      }

    }

  }

})

猜你喜欢

转载自blog.csdn.net/weixin_46501763/article/details/128161915