Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imported modules from monorepo does not trigger hot reload #352

Closed
smtrd3 opened this issue Apr 13, 2021 · 2 comments
Closed

Imported modules from monorepo does not trigger hot reload #352

smtrd3 opened this issue Apr 13, 2021 · 2 comments

Comments

@smtrd3
Copy link

smtrd3 commented Apr 13, 2021

I have the following following webpack config

const path = require('path');
const ReactRefreshPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');

// Current working directory
const BASE_PATH = process.cwd();

// Get path relative to current working directory
const getPath = _path => path.join(BASE_PATH, _path);

const isDevelopment = process.env.NODE_ENV !== 'production';

module.exports = {
  mode: isDevelopment ? 'development' : 'production',
  entry: {
    main: [
      `${require.resolve('webpack-hot-middleware/client')}?path=http://localhost:3000/__webpack_hmr`,
      './src/index.js'
    ],
  },
  target: 'web',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/',
  },
  devtool: 'cheap-module-source-map',
  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        include: modulePath => {
          return modulePath.includes(getPath('..')) || modulePath.includes(getPath('./src'))
        },
        use: {
          loader: require.resolve('babel-loader'),
          options: {
            presets: [
              require.resolve('@babel/preset-react'),
              [
                require.resolve('@babel/preset-env'), { targets: "defaults" },
              ],
              require.resolve('@babel/preset-typescript'),
            ],
            plugins: [
              require.resolve('react-refresh/babel'),
            ],
          }
        }
      }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new ReactRefreshPlugin({
        overlay: false,
    }),
    new HtmlWebpackPlugin({
      template: './index.html',
    }),
  ],
  resolve: {
    alias: {
      '@project': getPath('..')
    },
    modules: ['node_modules', getPath('../../node_modules')],
    extensions: ['.js', '.jsx', '.ts', '.tsx'],
  },
};

I am using the above config from a cli script hence the use of cwd. The issue I am facing is whenever I make changes to module other than the currently compiled module, fast refreshing does not work. Following is the log from browser

client.js:95 [HMR] connected
client.js:250 [HMR] bundle rebuilt in 114ms
client.js:241 [HMR] bundle rebuilding
client.js:250 [HMR] bundle rebuilt in 208ms
process-update.js:51 [HMR] Checking for updates on the server...
process-update.js:125 [HMR] Updated modules:
process-update.js:127 [HMR]  - ../library/lib.ts
process-update.js:132 [HMR] App is up to date.
client.js:250 [HMR] bundle rebuilt in 208ms

As can be seen above, the changes are detected but the components remain unchanged. The modules loaded from current working directory works as expected.

@pmmmwh
Copy link
Owner

pmmmwh commented May 4, 2021

Can you provide me a reproducible example? If you output the development Webpack bundle to disk, do you see the injected runtime code from this plugin in your monorepo imports? (It would be some react-refresh variables, etc.)

@pmmmwh
Copy link
Owner

pmmmwh commented Sep 4, 2021

Using the latest RC this is no-longer an issue.

@pmmmwh pmmmwh closed this as completed Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants