Skip to content

vue-cli4 热更新失效无法自动刷新的问题 #51

Description

@webplus

devServe配置没毛病,但就是没法热更新

// devServe配置没毛病
return {
    disableHostCheck: true,
    open: false,
    host: '0.0.0.0',
    port: ENV.VUE_APP_PORT,
    https: false,
    hotOnly: true,
    clientLogLevel: 'warn',
    overlay: {
      warnings: true,
      errors: true,
    },
    before: (app) => {
      VUE_APP_USE_MOCK === 'TRUE' && app.use(mockMiddleware());
    },
    historyApiFallback: {
      rewrites: [
        {
          from: /.*/,
          to: path.posix.join('/', 'index.html'),
        },
      ],
    },

解决方法:config.resolve.symlinks(true);

chainWebpack: config => {
    // 修复HMR
    config.resolve.symlinks(true);

    // config.plugins.delete('preload');
    // config.plugins.delete('prefetch');

    config
      .plugin("ignore")
      .use(
        new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn$/)
      );

    // 添加别名
    config.resolve.alias
      ....

vue.config.js其它配置可以参考,全面配置

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions