0

我有一个需要window.Reactand的应用程序window.ReactDOM,所以我修改了 next.config.js 中的 webpack externals 字段,如下所示:

// next.config.js
/** @type {import('next').NextConfig} */
module.exports = {
  reactStrictMode: true,
  webpack(config, { isServer }) {
    if (!isServer) {
      config.externals = {
        next: 'next',
        react: 'React',
        'react-dom': 'ReactDOM'
      }
    }
    return config;
  }
}

但是当我这样做时,编辑代码时页面无法热重新加载。Chrome 控制台面板中没有警告或错误。只有当我手动刷新页面时,最新的代码才能正常工作。

复制仓库:https ://github.com/MrKou47/nextjs-hmr-notwork-demo

4

0 回答 0