mitodl / ocw-hugo-themes

A Hugo theme for building OCW websites
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

Hash static assets using Webpack #1272

Closed ibrahimjaved12 closed 1 year ago

ibrahimjaved12 commented 1 year ago

What are the relevant tickets?

Partial solution to #1212

Description (What does it do?)

This PR does some webpack related modifications. This PR was made pertaining to the discussion we had for https://github.com/mitodl/ocw-hugo-themes/pull/1259#discussion_r1370219275

These are the pointers:

  1. We stop using @types for all webpack related modules. Webpack ^5 implicitly has all the stuff, so we no longer require @types/dotenv-webpack, @types/webpack-bundle-analyzer, @types/webpack-dev-server.
  2. We also remove assets-webpack-plugin (which was previously responsible for generating webpack.json)
  3. We now use webpack-manifest-plugin to generate webpack.json instead. This is done to have key-value pairs from unhashed file name to hashed file name.
  4. In particular, we hash 3 more things now: fonts, images and mathjax. Other stuff like css or js is already hashed in production. (Source: webpack.common.ts)
  5. We then use hashed static assets in partials through webpack's key-value pairs. Source: get_asset_webpack_url.html

How can this be tested?

Because of the nature of changes involved (manually modifying URL for all the static assets), we should make sure that there's no typo anywhere and the changes are working as expected.

Checkout to this branch Test in online / offline themes (www and course). Check for major functionalities such as videojs, nanogallery2, check for JS functionalities, make sure all the static assets are working fine. You can use this course perhaps: 16.885j-fall-2005 --> related resources (both nanogallery2 and videojs in 1 place).

github-actions[bot] commented 1 year ago

Netlify Deployments:
www: https://ocw-hugo-themes-www-pr-1272--ocw-next.netlify.app/
Course v2: https://ocw-hugo-themes-course-v2-pr-1272--ocw-next.netlify.app/