Dmitrii Vinokurov
Dmitrii Vinokurov

Reputation: 395

How to make React to ignore some folder files updates and don't recompile?

I've got problem - on some requests backend creates static html files in frontend subfolder which causes React to recompile and reload page. This is bad for me.

If simplify, I've got following project directory structure:

backend/
  ...
frontend/
  node_modules/
  package.json
  package-lock.json
  public/
    statements/
    ...
  src/
  webpack.config.js
  ...
...

I want React to ignore public/statements folder updates.

How could I make it?

Found that maybe I should configure Webpack exlude rule, but I failed to do it.

UPD1: Here is my webpack.config.js:

module.exports = {
  module: {
    rules: [
        {
            loader: 'babel-loader',
            test: /\.jsx?$/,
            exclude: /public/
        }
    ]
  }
};

UPD2: Tried also this one, same trouble:

const path = require('path');

module.exports = {
    devServer: {
        watchOptions: {
            ignored: [
                path.resolve(__dirname, 'public', 'statements'),
            ]
        }
    }
};

Upvotes: 1

Views: 4637

Answers (2)

Tom Shaw
Tom Shaw

Reputation: 1712

For HMR reloading?

devServer: {
  watchOptions: {
    ignored: [
      path.resolve(__dirname, 'public', 'statements'),
    ]
  }
}

Upvotes: 1

Bilal Hussain
Bilal Hussain

Reputation: 572

in the webpack.config.js file set the rules property array and set exclude folder like this

 module: {
  rules: [{
    loader: 'babel-loader',
    test: /\.js$/,
    exclude: /public/statements/
  }

Upvotes: 1

Related Questions