Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

vue-cli3新建的项目hotOnly: true报错,注掉后又不能热更新

vue create创建项目,自己选的配置。然后运行报错如下:
image

但是把devServer的hotOnly给注掉后,项目不报错可以正常启动了,但是热更新是无效的,得手动刷新,vue.config.js配置如下:

module.exports = {
  publicPath: '/datav-project/',
  assetsDir: 'static',
  devServer: {
    host: "0.0.0.0",
    port: 9527, // 端口号
    https: false, // https:{type:Boolean}
    open: true,
    hotOnly: true, // 热更新
    proxy: { //配置自动启动浏览器
      '/api': {
        target: process.env.VUE_APP_BASE_API, 
        changeOrigin: true, //允许跨域,如果接口跨域,需要进行这个参数配置
        secure: false, //如果是https接口,需要配置这个参数
        ws: false
      }
    }
  },
  lintOnSave: false,
  configureWebpack: (config) => {
    config.performance = {
      hints: false
    }
    config.externals = {
      'vue': 'Vue',
      'vue-router': 'VueRouter',
      'axios': 'axios',
      'echarts': 'echarts',
      'js-cookie': 'Cookies'
    }
  },
  chainWebpack (config) {
    config.resolve.symlinks(true); // 修复热更新失效
    config.plugins.delete('preload') // TODO: need test
    config.plugins.delete('prefetch') // TODO: need test
    config.resolve.alias.set('src', resolve('src'))
    config.plugin('compressionPlugin')
      .use(new CompressionPlugin({
        test: /.js$|.html$|.css/, // 匹配文件名
        threshold: 1024, // 对超过10k的数据压缩
        deleteOriginalAssets: false // 不删除源文件
      }))
  }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...