Webpacker: Webpack 3 support

Created on 20 Jun 2017  路  6Comments  路  Source: rails/webpacker

Most helpful comment

I did a little bit of testing with both a new rails app and a product I've been working on (a mature codebase running rails 5.1). Despite a few dependency warnings from a few packages (see below), webpack 3.0.0 seems to be working perfectly. In fact, because of the way webpack itself is installed by the webpacker gem, it will install 3.0.0 automatically starting today. The code that causes this is here, from lib/install/template.rb:

```puts "Installing all JavaScript dependencies"
run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
"webpack-manifest-plugin [email protected] coffee-loader coffee-script " \
"babel-core babel-preset-env babel-polyfill compression-webpack-plugin rails-erb-loader glob " \
"extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
"postcss-loader postcss-cssnext postcss-smart-import resolve-url-loader " \
"babel-plugin-syntax-dynamic-import babel-plugin-transform-class-properties " \
"babel-plugin-transform-object-rest-spread"

You'll see that it adds no specific version of webpack, which will make yarn install 3.0.0 at the time of this writing. This is perhaps something that should be fixed by version locking webpack in the installer template, and I'd be happy to work on a pull request to do just that. 

#### Dependency version warnings

When creating a new rails app, you may see a few dependency warnings caused by some packages declaring a requirement of `webpack@2`. This is a chunk of the install log detailing the packages that do:

```warning "[email protected]" has incorrect peer dependency "webpack@2".
warning "[email protected]" has incorrect peer dependency "webpack@^2.2.0".
warning "[email protected]" has incorrect peer dependency "webpack@2".
warning "[email protected]" has incorrect peer dependency "webpack@^2.2.0".
warning "[email protected]" has incorrect peer dependency "webpack@1 || ^2.1.0-beta || ^2.2.0-rc.0".

TL;DR - Webpack 3.0 works fine, but a few things should probably change in the webpacker install template to make sure that a) it is locked to a specific version of webpack, b) it installs versions of packages that already have declared explicit support for webpack 3.0.0.

All 6 comments

I did a little bit of testing with both a new rails app and a product I've been working on (a mature codebase running rails 5.1). Despite a few dependency warnings from a few packages (see below), webpack 3.0.0 seems to be working perfectly. In fact, because of the way webpack itself is installed by the webpacker gem, it will install 3.0.0 automatically starting today. The code that causes this is here, from lib/install/template.rb:

```puts "Installing all JavaScript dependencies"
run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
"webpack-manifest-plugin [email protected] coffee-loader coffee-script " \
"babel-core babel-preset-env babel-polyfill compression-webpack-plugin rails-erb-loader glob " \
"extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
"postcss-loader postcss-cssnext postcss-smart-import resolve-url-loader " \
"babel-plugin-syntax-dynamic-import babel-plugin-transform-class-properties " \
"babel-plugin-transform-object-rest-spread"

You'll see that it adds no specific version of webpack, which will make yarn install 3.0.0 at the time of this writing. This is perhaps something that should be fixed by version locking webpack in the installer template, and I'd be happy to work on a pull request to do just that. 

#### Dependency version warnings

When creating a new rails app, you may see a few dependency warnings caused by some packages declaring a requirement of `webpack@2`. This is a chunk of the install log detailing the packages that do:

```warning "[email protected]" has incorrect peer dependency "webpack@2".
warning "[email protected]" has incorrect peer dependency "webpack@^2.2.0".
warning "[email protected]" has incorrect peer dependency "webpack@2".
warning "[email protected]" has incorrect peer dependency "webpack@^2.2.0".
warning "[email protected]" has incorrect peer dependency "webpack@1 || ^2.1.0-beta || ^2.2.0-rc.0".

TL;DR - Webpack 3.0 works fine, but a few things should probably change in the webpacker install template to make sure that a) it is locked to a specific version of webpack, b) it installs versions of packages that already have declared explicit support for webpack 3.0.0.

@gauravtiwari @dhh do you guys have any idea of how you'd like versioning to work in the webpacker gem? Should it follow webpack versioning, or do you have a different philosophy you'd apply here?

I wanted to create a pull request that would update webpacker with explicit support for webpack 3, but one of the key things I'd like to do is to lock down the version of webpack we install (as I outline above, it is unlocked). It might be confusing for developers using this gem if the version numbers between it and webpack are very different, but at the same time, it seems like webpack is stepping away from semver. Any thoughts?

I don't think we should tie Webpacker and Webpack together on the versioning side. Too hard to keep things in proper sync anyway. I think we should keep up with Webpack as far as possible and be on the latest stable version 馃憤

Makes sense since we haven't followed versioning so far and it would be confusing if we follow now. Webpack is just compiler so versions really don't matter - the latest is always better 馃槃 . Hopefully the warnings will go away once other packages adapt Webpack 3.0.

@fredoliveira Feel free to make a PR for Webpack 3.0 additions though 馃憤

Closing this in anticipation of a PR making the 3.0 changes.

Was this page helpful?
0 / 5 - 0 ratings