简体   繁体   English

nx 反应模块联合热重载

[英]nx react module federation hot reload

I'm using module federation with nx and want to enable HMR.我正在使用带有 nx 的模块联合并希望启用 HMR。 I applied the hmr: true option in both project.json files.我在两个project.json文件中应用了hmr: true选项。 (for the host and the remote). (对于主机和远程)。 The problem that its working only for the remote, and when changing the code in the host project its not working and not updating it in the browser.它仅适用于远程的问题,并且在更改宿主项目中的代码时它不起作用并且没有在浏览器中更新它。

this is the configuration for the host project.json (I'm using nx server ):这是主机project.json的配置(我使用的是nx server ):

"serve": {
  "executor": "@nrwl/react:module-federation-dev-server",
  "defaultConfiguration": "development",
  "options": {
    "buildTarget": "client:build",
    "hmr": true,
    "port": 4200
  },
  "configurations": {
    "development": {
      "buildTarget": "client:build:development",
      "open": true,
      "watch": true,
      "liveReload": true
    },
    "production": {
      "buildTarget": "client:build:production",
      "hmr": false
    }
  }
}

and this is in the remote project.json这是在远程project.json

"serve": {
  "executor": "@nrwl/react:module-federation-dev-server",
  "defaultConfiguration": "development",
  "options": {
    "buildTarget": "assets:build",
    "hmr": true,
    "port": 4201
  },
  "configurations": {
    "development": {
      "buildTarget": "assets:build:development"
    },
    "production": {
      "buildTarget": "assets:build:production",
      "hmr": false
    }
  }
}

It's not working with HMR.它不适用于 HMR。 Well never got to make it work.好吧,从来没有让它发挥作用。 But using live reload witht following config its working fine.但是使用实时重新加载并遵循配置它工作正常。 I can even debug TS with source maps.我什至可以使用源映射调试 TS。

module.exports = merge(custom, common, {
  mode: 'development',
  output: {
    filename: '[name].[contenthash].js',
    path: path.join(__dirname, 'dev'),
    publicPath: 'auto',
  },
  devServer: {
    static: path.join(__dirname, 'dev'),
    hot: false,
    liveReload: true,
    port: infinisoft.moduleFederation.devport
  },
  plugins: [
    new MFLiveReloadPlugin({
      port: infinisoft.moduleFederation.devport,
      container: name,
      standalone: true
    }),
    new ReactRefreshWebpackPlugin(),
    new MinChunkSizePlugin({
      minChunkSize: 10000, // Minimum number of characters
    }),
    moduleFederation,
    new MiniCssExtractPlugin(),
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, 'src', 'config', 'index.html'),
    }),
  ],
  devtool: 'source-map',
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM