Skip to content

Fix: webpack optimizations for JS#2235

Merged
dac09 merged 3 commits intoredwoodjs:mainfrom
dac09:fix/webpack-optimizations-minimizer
Apr 12, 2021
Merged

Fix: webpack optimizations for JS#2235
dac09 merged 3 commits intoredwoodjs:mainfrom
dac09:fix/webpack-optimizations-minimizer

Conversation

@dac09
Copy link
Copy Markdown
Contributor

@dac09 dac09 commented Apr 8, 2021

What?

JS wasn't being minified on yarn rw build web.

Adds TerserPlugin to optimizations stage in webpack config to perform minification.

Note: I intentionally didn't enabled the parallel: true flag, because as noted in their docs on CircleCI for example, it causes issues.

@dac09 dac09 requested a review from peterp April 8, 2021 17:03
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2021

📦 PR Packages

Click to Show Package Download Links

https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/create-redwood-app-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-api-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-api-server-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-auth-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-cli-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-core-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-dev-server-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-eslint-config-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-eslint-plugin-redwood-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-forms-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-internal-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-prerender-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-router-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-structure-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-testing-0.29.0-a6d032f.tgz
https://rw-pr-redwoodjs-com.s3.amazonaws.com/2235/redwoodjs-web-0.29.0-a6d032f.tgz

Install this PR by running yarn rw upgrade --pr 2235:0.29.0-a6d032f

name: (entrypoint) => `runtime-${entrypoint.name}`,
},
minimizer: [isEnvProduction && new CssMinimizerPlugin()].filter(Boolean),
minimizer: [new CssMinimizerPlugin(), new TerserPlugin()],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could this lead to a performance impact during development? 🤷‍♂️

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is what I thought originally as well (and had the env check)

But looking further into the docs there was this one line in the TerserPlugin docs:

Since version 4 webpack runs optimizations for you depending on the chosen mode, still all optimizations are available for manual configuration and overrides.

And the docs here: https://webpack.js.org/configuration/mode/

But webpack is confusing and maybe I'm wrong 😑.

So what I think happens is in mode dev, minimize gets set to false so these plugins never get run.

Is there a good way to verify this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmpf, that is super confusing... they're run based on the mode, but they're also configurable manually? I wonder what they mean by that... I think we are configuring them manually here.

I guess you could see if the output bundles are minified in development mode, which would indicate that it's running when it shouldn't be.
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know if source maps are applied to the response 🤷

Copy link
Copy Markdown
Contributor Author

@dac09 dac09 Apr 12, 2021

Choose a reason for hiding this comment

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

Hey @peterp can confirm no minimising on the dev server:
image

To confirm I've linked the project correctly:

❯ cat node_modules/@redwoodjs/core/config/webpack.common.js | grep minimizer:
      minimizer: [new CssMinimizerPlugin(), new TerserPlugin()],

Copy link
Copy Markdown
Contributor Author

@dac09 dac09 Apr 12, 2021

Choose a reason for hiding this comment

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

My understanding of why this works btw:

  1. When mode isn't production, webpack automatically sets the flag minimize (not not minimizer) to false
  2. When optimization.minimize is false, optimization.minizer is ignored

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, could you leave a comment nearby minimizer so that we don't assume that it's running in dev mode in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You bet ☑️

@dac09 dac09 added this to the patch milestone Apr 10, 2021
@dthyresson dthyresson added the topic/config Babel, Webpack, ESLint, Prettier, etc. label Apr 11, 2021
@dac09 dac09 force-pushed the fix/webpack-optimizations-minimizer branch from b08e8d5 to 7ab07e2 Compare April 12, 2021 16:26
@dac09 dac09 merged commit 73c7887 into redwoodjs:main Apr 12, 2021
@dac09 dac09 deleted the fix/webpack-optimizations-minimizer branch April 12, 2021 17:29
thedavidprice pushed a commit that referenced this pull request Apr 15, 2021
* Add terser for JS minification

* Downgrade terser to 4.x, 5+ not supported on webpack 4

* Add comment about webpack modes
peterp added a commit that referenced this pull request Apr 16, 2021
* upgrade Prisma v2.21.0 (#2273)

Co-authored-by: Daniel Choudhury <[email protected]>

* Fix: webpack optimizations for JS (#2235)

* Add terser for JS minification

* Downgrade terser to 4.x, 5+ not supported on webpack 4

* Add comment about webpack modes

* Adds better messages for rwt link | Watcher does not exist on build failure | Only remove node_modules after a succesful framework build (#2269)

* fix(cli): Cli package should depend on api server explicitly (#2251)

* upgrade prisma v2.21.2 (#2280)

* v0.30.0

Co-authored-by: David Price <[email protected]>
Co-authored-by: Daniel Choudhury <[email protected]>
thedavidprice added a commit that referenced this pull request Apr 20, 2021
* upgrade Prisma v2.21.0 (#2273)

Co-authored-by: Daniel Choudhury <[email protected]>

* Fix: webpack optimizations for JS (#2235)

* Add terser for JS minification

* Downgrade terser to 4.x, 5+ not supported on webpack 4

* Add comment about webpack modes

* Adds better messages for rwt link | Watcher does not exist on build failure | Only remove node_modules after a succesful framework build (#2269)

* fix(cli): Cli package should depend on api server explicitly (#2251)

* upgrade prisma v2.21.2 (#2280)

* v0.30.0

* v0.30.1

* Update packages/api/package.json

* Update packages/cli/package.json

* Update packages/dev-server/package.json

* Update packages/create-redwood-app/package.json

* Update packages/cli/package.json

* Update packages/create-redwood-app/package.json

* update crwa/template/yarn.lock to v0.30.1

Co-authored-by: Daniel Choudhury <[email protected]>
Co-authored-by: Peter Pistorius <[email protected]>
dac09 added a commit to dac09/redwood that referenced this pull request Apr 21, 2021
…erve-web

* 'main' of github.com:redwoodjs/redwood: (40 commits)
  Support generating typescript cells and pages | Autodetect ts project (redwoodjs#2279)
  create-redwood-app messages: moved app start commands to end (redwoodjs#2278)
  Add import type to configuration files (redwoodjs#2214)
  Bump @reach/skip-nav from 0.13.2 to 0.15.0 (redwoodjs#2237)
  Adding Setup Deploy Render Command (redwoodjs#2099)
  Disable role linting in Routes (redwoodjs#2318)
  v0.30.1 (redwoodjs#2322)
  teardown should attempt to delete dbName table (redwoodjs#2083)
  Restore @storybook/addon-a11y (redwoodjs#2309)
  fix(auth): Implement automatic token refresh on supported providers (redwoodjs#2277)
  fix(cli): move api-server dep from api to cli (redwoodjs#2307)
  Static typing for cells (redwoodjs#2208)
  Recommended Babel package upgrades (dependabot) (redwoodjs#2255)
  v0.30.0 (redwoodjs#2301)
  upgrade Prisma v2.21.0 (redwoodjs#2273)
  Further improvements to CONTRIBUTING.md (redwoodjs#2261)
  Adds better messages for rwt link | Watcher does not exist on build failure | Only remove node_modules after a succesful framework build (redwoodjs#2269)
  Update named param types in router readme (redwoodjs#2262)
  Bump core-js from 3.6.5 to 3.10.1 (redwoodjs#2243)
  Fix: webpack optimizations for JS (redwoodjs#2235)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic/config Babel, Webpack, ESLint, Prettier, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants