Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Support Webpack 2 #74

Closed
wants to merge 1 commit into from
Closed

Support Webpack 2 #74

wants to merge 1 commit into from

Conversation

davetron5000
Copy link

@davetron5000 davetron5000 commented Dec 16, 2016

These are (obviously) breaking, but fairly minimal.

I applied these changes to my own app based on the migrating guide and what this gem puts into the initial config is fairly minimal, so the changes are not that great.

I think the best thing to do right now with this PR is to have others try it. It's obviously not releasable in its current state because of the RC dependency.

Another question is: when Webpack 2 is released, should this gem support both versions? If so, I'm guessing we'll need to have a bit more code to allow the user to choose which version.

Fixes #73

"stats-webpack-plugin": "^0.2.1",
"webpack": "^1.9.11",
"webpack-dev-server": "^1.9.0"
"stats-webpack-plugin": "*",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no release of this plugin that supports 2.2.0-rc.0 explicitly. It currently requires 2.2.0-beta. I honestly don't know what this even does, but nothing broke locally for me.

I'm guessing the steady-state of this might look like:

{
  "stats-webpack-plugin": "^0.x.y", // whatever version is compatible
  "webpack": "^2.2",
  "webpack-dev-server": "^2.2"
}

(Note that I'm not super-familiar with node best practices for versioning—I'm trying to express "2.2 and above but not 3.0")

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stats-webpack-plugin is used by the dev server to produce the live manifest for the helper

@@ -54,8 +57,7 @@ if (production) {
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify('production') }
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin is included by default.

Copy link

@mkousta mkousta Jan 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the configuration for UglifyJsPlugin is also not necessary any more since the options passed above for warnings and sourcemaps are the default in webpack 2, see migration guide. I have tested making lines 50-53 just new webpack.optimize.UglifyJsPlugin(), in my rails app and it seems to be working as expected.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I've removed the superfluous config

@mipearson
Copy link
Owner

Another question is: when Webpack 2 is released, should this gem support both versions?

Right now I'm thinking that there will be a "If you'd like to use webpack 2, use gem version x or below" notice.

@davetron5000
Copy link
Author

OK, I've squashed and repushed now that webpack 2 is officially released.

I have tested this locally and it works the same as before, but uses webpack 2. woot!

Would love a review and release. My book that uses this is in copyediting so I'd love to be able to change it to use a released version of this plugin.

"stats-webpack-plugin": "^0.4.3",
"webpack": "^1.14.0",
"webpack-dev-server": "^1.16.2"
"stats-webpack-plugin": "*",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not loving this, but since we're now using yarn, not as worried about open-ended deps

@davetron5000 davetron5000 changed the title [WIP] changes to support Webpack 2 Support Webpack 2 Feb 18, 2017
@davetron5000
Copy link
Author

Anything I can do to get this released?

@mipearson
Copy link
Owner

@davetron5000 We've got webpack 2 working internally with this gem at marketplacer - I need to set up a test environment to confirm that this change works on its own and also make a decision regarding Webpack 1 support.

@davetron5000
Copy link
Author

Cool. I hd it working with the sample app in my book as well. I'd like to be able to just tell readers "use webpack-rails" and not "use this branch/sha-1 of webpack-rails". But I know my book release timeline isn't your top priority :)

If you want my thoughts on webpack 1 (even though didn't ask :), it's: don't support it directly. Reasons:

  • webpack adoption in Rails-land has to be light, so Webpack 2 is much more likely to be used
  • this gem should not have a lot of churn, so locking to a lower version for Webpack 1 support isn't terribly dangerous
  • Rails 5.1 will ship with its own solution to this problem, so this gem might not be needed for 5.1 and beyond.

@troglotit
Copy link

Excuse me for intervention, I wanted to comment on Rails 5.1 webpack solution. It'll be based on webpacker. This gem says in readme:

as the purpose is only to use Webpack for app-like JavaScript, not images, css, or even JavaScript Sprinkles (that all continues to live in app/assets).

Which means they aren't going to explicitly support require('Components.css') and images and many other things. That's why I'm glad to use this gem and I hope it'll continue to develop ❤️ .

@justin808
Copy link

@troglotit, @davetron5000 @mipearson The former assumption Webpacker not supporting non JS assets is changing. I'm getting involved in the Webpacker project, and I intend to have React on Rails support it. Please see my thoughts on this topic: rails/webpacker#139. I look forward to any comments on this topic and if anybody wants an invite to our Slack room for ShakaCode, please email me at [email protected].

@davetron5000
Copy link
Author

I had assumed webpack's existence in a rails project could allow it to do whatever, and that webpacker would simply optimize an initial configuration for "app-like javascript". In other words, Rails 5.1 should not really need this gem I don't think.

@mipearson
Copy link
Owner

Just want to drop a note here for people looking at this and wondering when the gem will support webpack 2: it supports it today, we're using it in production, it's just that the default configuration generated is for webpack 1.

@davetron5000
Copy link
Author

Hi, I had to create a fork with my changes on it so I could send my book to copyediting. I needed the book to support webpack 2 and did not want to require the user to use this gem, erase the configuration it generated for them, and create it from scratch. I now this is fairly annoying—I'll try to keep things in sync.

Don't write a book about JavaScript :)

@troglotit
Copy link

troglotit commented Mar 13, 2017

Hey, I've started using this patch in my project, and everything seems to work. But take it with grain of salt: my project is not in production yet and I haven't used webpack before, although I really did dig into it, alsoNODE_ENV == production build seem to work as well 😄 . Hope more people will give it a try.

One line which I changed is I removed DedupePlugin as it said in https://webpack.js.org/guides/migrating/#dedupeplugin-has-been-removed

@davetron5000
Copy link
Author

I'm using Webpacker now, so don't need this merged. Gonna close it as it's getting pretty old, but feel free to use this if you like for a future PR

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants