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

Upgrade to webpack 2 #2380

Merged
merged 30 commits into from
May 17, 2017
Merged

Upgrade to webpack 2 #2380

merged 30 commits into from
May 17, 2017

Conversation

kumar303
Copy link
Contributor

@kumar303 kumar303 commented May 12, 2017

Fixes mozilla/addons#10112

Webpack 1 to 2 migration guide: https://webpack.js.org/guides/migrating/

Here's what I tested:

  • npm run dev:amo, npm run unittest:dev, bin/extract-locales
  • reloading JS and CSS
  • source maps

I had trouble getting npm run start to work to mimic production. Doing npm run build is fine and the server starts but the bundle URLs are a 404. How do you simulate the CDN locally? I see the bundle files in dist but I'm not sure how to serve them. Is there a special value to use for amoCDN and staticHost in the config?

I also had trouble figuring out how to test that the postcss-loader is working. Any ideas?

package.json Outdated
@@ -285,15 +285,15 @@
"semver": "^5.3.0",
"shelljs": "^0.7.7",
"sinon": "^2.2.0",
"sri-stats-webpack-plugin": "^0.7.3",
"sri-stats-webpack-plugin": "github:sopherio/sri-stats-webpack-plugin#f23de19e1d84dab50e59076e05bcafa508ba64c4",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is pretty unfortunate since the patch to make it webpack 2 compatible is just a dependency bump. More info: mikechau/sri-stats-webpack-plugin#71

Copy link
Contributor

@muffinresearch muffinresearch May 15, 2017

Choose a reason for hiding this comment

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

I wonder if we should consider an alternative lib e.g: https://github.com/waysact/webpack-subresource-integrity (there might be others, though this says it supports both webpack1 and 2).

The bit I'm not keen on is that this change relies on a fork, which in turn loads another fork. Whilst you've been able to specify a hash in the first case, you can't in the second. To fix potential integrity issue we'd need to have our own forks or, it might be easier to use something else?

@kumar303 kumar303 requested a review from muffinresearch May 12, 2017 22:51
plugins: [
new webpack.DefinePlugin({
CLIENT_CONFIG: JSON.stringify(clientConfig),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the shared getPlugins() array, the process.env.NODE_ENV value is added to DefinePlugin unlike before. This doesn't seem to cause any problems though.

// Replaces server config module with the subset clientConfig object.
new webpack.NormalModuleReplacementPlugin(
/config$/, 'core/client/config.js'),
// Substitutes client only config.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment should be updated to refer to logging.

test: /\.jpg$/,
use: [{
loader: 'url-loader',
options: { limit: 10000, mimetype: 'image/jpeg' },
Copy link
Contributor

Choose a reason for hiding this comment

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

10000 could be a const at the top of the file.

@@ -27,7 +24,9 @@ for (const app of appsBuildList) {
const settings = {
devtool: 'source-map',
context: path.resolve(__dirname),
progress: true,
devServer: {
progress: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this setting relate to - is it ok in a prod config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's just for the webpack dev server. I can just move it to the dev config though.

test: /\.svg$/,
use: [{ loader: 'svg-url-loader', options: { limit: 10000 } }],
}, {
test: /\.jpg$/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work on the DRY'ing up.

silicagelpack

...styleRules,
{
test: /\.svg$/,
use: [{ loader: 'svg-url-loader', options: { limit: 10000 } }],
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a mimetype added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just read the docs on these loaders. I can add one here but why are we specifying mime types at all? The docs say that a mime type is inferred from file extension.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not needed then that's less code to maintain here 👍

@muffinresearch muffinresearch requested a review from tofumatt May 15, 2017 10:52
options: {
context: path.resolve(__dirname),
postcss: [
autoprefixer({ browsers: ['last 2 versions'] }),
Copy link
Contributor

Choose a reason for hiding this comment

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

One way it should be possible to know this is working is that if when it's disabled via conf the CSS should be smaller. That does assume there's something in the CSS that would need to be prefixed with though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it's working. I searched -ms-flex-pack in dist/amo-eb2fa8bf265a819a3276f84cff2ff9b2.css before and after to verify.

@muffinresearch
Copy link
Contributor

This is great - I made some comments, I think it might be nice to switch out the sri plugin to something better maintained.

I also added @tofumatt to the reviewers since more eyes on this the merrier.

This is probably one to land after the tag just so there's more time to fix up any nits that come up in use.

@kumar303
Copy link
Contributor Author

kumar303 commented May 16, 2017

@muffinresearch I was able to switch us to webpack-subresource-integrity but unfortunately it took some custom code. Can you take another look? The switch occurred in eb720de

@kumar303 kumar303 requested a review from muffinresearch May 16, 2017 22:19
@kumar303
Copy link
Contributor Author

I had to do some fix-ups so I guess you'll have to dig for it in the diff: https://github.com/mozilla/addons-frontend/pull/2380/files#diff-c325001c4cdd93809a99cbe1cb1b201cR10

Copy link
Contributor

@muffinresearch muffinresearch left a comment

Choose a reason for hiding this comment

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

Looks good to me, I think it would make sense to land this and maximise the time to run it and iron out any kinks in-use.

@kumar303 kumar303 merged commit 3502279 into mozilla:master May 17, 2017
@kumar303 kumar303 deleted the webpack2-iss1761 branch May 17, 2017 21:07
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

Successfully merging this pull request may close these issues.

Upgrade to webpack 2
2 participants