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

Make compatible with webpack-dev-server 4.0.0 #2994

Closed
anark opened this issue Apr 25, 2021 · 13 comments
Closed

Make compatible with webpack-dev-server 4.0.0 #2994

anark opened this issue Apr 25, 2021 · 13 comments

Comments

@anark
Copy link
Contributor

anark commented Apr 25, 2021

webpack-dev-server has a new beta release(4.0.0-beta.2) that features built in webpack 5 support.

Would be great to make webpacker 6.0 compatible with this as well
https://github.com/webpack/webpack-dev-server/blob/master/CHANGELOG.md#400-beta0-2020-11-27

@vladimirtemnikov
Copy link

And it has much less dependencies ;)

@navidemad
Copy link

Is there any news about this issue :) ?

@jcoyne
Copy link
Contributor

jcoyne commented Jul 7, 2021

Yes, #3057 is one thing that has to be done. Another issue I ran into is that watchOptions (

watchOptions: devServer.watch_options
) isn't supported in webpack-dev-server 4.

@clinejj
Copy link

clinejj commented Jul 7, 2021

Here's my config/webpack/development.js that I got working with webpack-dev-server 4.0rc0 that maps the current configuration onto the new configuration:

NOTE: updated Aug 2 to support weback-dev-server 4.0rc0

process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const webpackConfig = require('./base')

const devServerConfig = {
  client: {
    logging: webpackConfig.devServer.clientLogLevel,
    overlay: webpackConfig.devServer.overlay,
  },
  compress: webpackConfig.devServer.compress,
  devMiddleware: {
    publicPath: webpackConfig.devServer.publicPath,
  },
  hot: webpackConfig.devServer.injectHot,
  host: webpackConfig.devServer.host,
  port: webpackConfig.devServer.port,
  https: webpackConfig.devServer.https,
  hot: webpackConfig.devServer.hot,
  historyApiFallback: webpackConfig.devServer.historyApiFallback,
  headers: webpackConfig.devServer.headers,
  static: [
    {
      directory: webpackConfig.devServer.contentBase,
      watch: true,
    }
  ],
};
if (webpackConfig.devServer.quiet) {
  webpackConfig.infrastructureLogging.level = 'none';
}
if (webpackConfig.devServer.useLocalIp) {
  devServerConfig.host = 'local-ip';
}
if (webpackConfig.devServer.disableHostCheck) {
  devServerConfig.allowedHosts = 'all';
}
webpackConfig.stats = webpackConfig.devServer.stats;
webpackConfig.devServer = devServerConfig;

module.exports = webpackConfig;

It's a bit tricky to parse the changed configurations from the changelog for wds, but this should handle it. If you have custom pack paths or a more advanced configuration you may want to verify that everything is being set correctly.

@tagliala
Copy link
Contributor

tagliala commented Aug 1, 2021

webpack-dev-server 4 entered the RC version stage

@anark
Copy link
Contributor Author

anark commented Aug 18, 2021

Webpack Dev Server 4 has now been released as a stable 4.0.0 release. What needs to be done to make webpacker compatible with webpack-dev-server@4.0.0

When I upgrade webpack-dev-server to 4.0.0 when using webpacker@6.0.0.rc.1 I get the folloing error

- options has an unknown property 'watchOptions'. These properties are valid:
object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, setupExitSignals?, static?, watchFiles?, webSocketServer? }

@anark anark changed the title Make compatible with webpack-dev-server 4.0 beta. Make compatible with webpack-dev-server 4.0.0 Aug 18, 2021
@clinejj
Copy link

clinejj commented Aug 18, 2021

The patch I posted above still works if you want to upgrade sooner, but when I briefly looked into this earlier rails/webpacker would need to update the following for more official support:

I don't have enough of an understanding on how the YML configuration gets passed through to the JS but I think those are the three main files that handle it.

@PikachuEXE
Copy link

There is a JS config file that read the "default config" from a YAML file with default config
Then the same config file read from your project's config file and merge values

So to get rid of the unwanted options either the user need an extra statement to remove it or update the default config file from webpack-dev-server

@RSO
Copy link
Contributor

RSO commented Aug 19, 2021

Here's my config/webpack/development.js that I got working with webpack-dev-server 4.0rc0 that maps the current configuration onto the new configuration:

NOTE: updated Aug 2 to support weback-dev-server 4.0rc0

process.env.NODE_ENV = process.env.NODE_ENV || 'development'

const webpackConfig = require('./base')

const devServerConfig = {
  client: {
    logging: webpackConfig.devServer.clientLogLevel,
    overlay: webpackConfig.devServer.overlay,
  },
  compress: webpackConfig.devServer.compress,
  devMiddleware: {
    publicPath: webpackConfig.devServer.publicPath,
  },
  hot: webpackConfig.devServer.injectHot,
  host: webpackConfig.devServer.host,
  port: webpackConfig.devServer.port,
  https: webpackConfig.devServer.https,
  hot: webpackConfig.devServer.hot,
  historyApiFallback: webpackConfig.devServer.historyApiFallback,
  headers: webpackConfig.devServer.headers,
  static: [
    {
      directory: webpackConfig.devServer.contentBase,
      watch: true,
    }
  ],
};
if (webpackConfig.devServer.quiet) {
  webpackConfig.infrastructureLogging.level = 'none';
}
if (webpackConfig.devServer.useLocalIp) {
  devServerConfig.host = 'local-ip';
}
if (webpackConfig.devServer.disableHostCheck) {
  devServerConfig.allowedHosts = 'all';
}
webpackConfig.stats = webpackConfig.devServer.stats;
webpackConfig.devServer = devServerConfig;

module.exports = webpackConfig;

It's a bit tricky to parse the changed configurations from the changelog for wds, but this should handle it. If you have custom pack paths or a more advanced configuration you may want to verify that everything is being set correctly.

Thanks for this! Just a small note for others trying this same snippet:

  1. hot: is set twice in the devServerConfig variable
  2. I changed watch: true to watch: webpackConfig.devServer.watchOptions so that it (hopefully) includes my ignores: /node_modules/ in there!

@anark
Copy link
Contributor Author

anark commented Aug 20, 2021

Thanks @RSO,
Those changes do work for me when I try to run it(as long as I remove react-refresh but I'll tackle that later).

However It would be better if webpacker users didn't have to use a custom config to use the latest webpack-dev-server. I think #3122 seems like a reasonable solution. That way when upgrading to webpacker 6.0 you would also upgrade to dev-server 4.0

@PikachuEXE
Copy link

Agree with @anark
webpacker 6.0 stable release is not made yet and it's fine we include more breaking changes.
Just need the migration doc to catch up

@PikachuEXE
Copy link

For those who want to try out #3122 I posted a comment in that PR
about the method, the result and a potential issue for webpacker/webpack-dev-server v4

@dhh
Copy link
Member

dhh commented Aug 25, 2021

Solved via #3122.

@dhh dhh closed this as completed Aug 25, 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

9 participants