question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable this plugin only during development mode

See original GitHub issue

hey

the https://github.com/jantimon/favicons-webpack-plugin is only generating the full favicon during production mode by default. so if you set mode: "development" it will not be active unless you overrule that setting.

what about adding something similar to ReactRefreshWebpackPlugin?

the api could look like this:

// Only active during development
new ReactRefreshWebpackPlugin()
// Active for dev and prod
ReactRefreshWebpackPlugin({
  alwaysEnabled: true
})

to find out wether you are in production mode or in dev mode you can use the following snippet inside any hook:

// From https://github.com/webpack/webpack/blob/3366421f1784c449f415cda5930a8e445086f688/lib/WebpackOptionsDefaulter.js#L12-L14
    const isProductionLikeMode =
      compiler.options.mode === 'production' || !compiler.options.mode;

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jantimoncommented, Aug 5, 2020

one more idea:

can we move all of this into the plugin?

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

module.exports = {
  // DO NOT apply the plugin in production mode!
  mode: isDevelopment ? 'development' : 'production',
  module: {
    rules: [
      // ... other rules
      {
        // for TypeScript, change the following to "\.[jt]sx?"
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: [
          // ... other loaders
          {
            loader: require.resolve('babel-loader'),
            options: {
              // ... other options
              // DO NOT apply the Babel plugin in production mode!
              plugins: [isDevelopment && require.resolve('react-refresh/babel')].filter(Boolean),
            },
          },
        ],
      },
    ],
  },
};

We could in the afterPlugins webpack hook iterate over all loaders - search for babel and check if it contains react-refresh/babel - if not push it.

So the webpack prod(disabled)/dev(enabled) config change to add the refresh plugin would look like this:

module.exports = {
  plugins: [
     new ReactRefreshWebpackPlugin()
  ]
}

That way it would even be cli compatible e.g.:

webpack --plugin react-refresh-webpack-plugin --mode production

or

webpack-dev-server --plugin react-refresh-webpack-plugin --mode development
1reaction
morriqcommented, Sep 27, 2021

I came here from react-hot-loader, and installation steps discourages me since it forces my configuration to check whether is production or development build.

In react-hot-loader it’s written:

The webpack patch, hot, Babel plugin, @hot-loader/react-dom etc. are all safe to use in production; they leave a minimal footprint, so there is no need to complicate your configuration based on the environment. Using the Babel plugin in production is even recommended because it switches to cleanup mode.

Please consider the same.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable Developer Mode, Install Plugin Loader & PowerTools ...
Kite is a free AI-powered coding assistant that will help you code faster and smarter. The Kite plugin integrates with all the top...
Read more >
Development mode - PF4J
In DEVELOPMENT mode you can developing plugins in a simple and fast mode. Lets describe how DEVELOPMENT runtime mode works. First, you can...
Read more >
Enable Dev Mode not working - WordPress.org
I can't enable dev mode either because a live account was partially connected. I emailed support and they only suggested to delete the...
Read more >
Disable UglifyJSPlugin when doing development work?
You could also make your config script generate a config object that only includes that plugin if you're running in production (eg.
Read more >
Mode | webpack
Sets process.env.NODE_ENV on DefinePlugin to value development . Enables useful names for modules and chunks. production ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found