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

Allow configuration of use of contentHash for development #234

Merged
merged 13 commits into from
Jun 22, 2023

Conversation

justin808
Copy link
Member

@justin808 justin808 commented Jan 8, 2023

Per #88

An experiment with adding a configuration to specify whether a contentHash is used.

Note, per webpack docs

Don't use contentHash except for production for performance.

So rather than turning contentHash back on for everybody, let's allow an easy override.

PR checklist:

  • Add test to check the addition of contentHash in dev env based on the config
  • Update documentation
  • Update changelog

Closes #88

@justin808 justin808 changed the title [WIP] Attempt to addres [WIP] Allow configuration of use of contentHash for development Jan 8, 2023
@ahangarha ahangarha self-assigned this Jun 14, 2023
@ahangarha ahangarha force-pushed the justin808/allow-config-useContentHash branch from 3e53256 to fad12e8 Compare June 14, 2023 13:57
@ahangarha ahangarha changed the title [WIP] Allow configuration of use of contentHash for development Allow configuration of use of contentHash for development Jun 16, 2023
@ahangarha
Copy link
Contributor

@justin808 we now have reasonable tests for this feature. So if there is no other concern, this PR should be ready for merge (or maybe we freeze the features on what we have in RC1 and add this feature later in 7.1. No rush.

Copy link
Member Author

@justin808 justin808 left a comment

Choose a reason for hiding this comment

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

see requests

const config = require('../config')
const { isProduction } = require('../env')
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

May you elaborate? isProduction checked nodeEnv already and it seems that is how we check the environment in on JS side. Before also we were adding content hash if isProduction was true.

Should I do anything different?

README.md Outdated
@@ -216,6 +216,8 @@ Webpack intelligently includes only necessary files. In this example, the file `

`nested_entries` allows you to have webpack entry points nested in subdirectories. This defaults to false so you don't accidentally create entry points for an entire tree of files. In other words, with `nested_entries: false`, you can have your entire `source_path` used for your source (using the `source_entry_path: /`) and you place files at the top level that you want as entry points. `nested_entries: true` allows you to have entries that are in subdirectories. This is useful if you have entries that are generated, so you can have a `generated` subdirectory and easily separate generated files from the rest of your codebase.

To enable/disable the usage of contentHash in any specific environment, add/modify `useContentHash` with a boolean value in `config/shakapacker.yml`. This feature is disabled for all environments except production by default. Notice that despite the possibility of enabling this option for the development environment, [it is not recommended](https://webpack.js.org/guides/build-performance/#avoid-production-specific-tooling).
Copy link
Member Author

Choose a reason for hiding this comment

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

not any, instead use 'in any NODE_ENV environment except production'

Add:

You may not disable the content hash for a NODE_ENV of production as that would break the browser caching of assets.

you cannot override for production

if (config.useContentHash === true) {
// eslint-disable-next-line no-console
console.warn(`⚠️ WARNING
Setting 'useContentHash' to 'false' in production environment is not allowed!
Copy link
Member Author

Choose a reason for hiding this comment

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

for a NODE_ENV of production

Production environment could mean RAILS_ENV or NODE_ENV, so that's ambiguous. NEVER be ambiguous.

@justin808 justin808 merged commit 776837c into master Jun 22, 2023
@justin808 justin808 deleted the justin808/allow-config-useContentHash branch June 22, 2023 06:45
Comment on lines +80 to +86
if (config.useContentHash === true) {
// eslint-disable-next-line no-console
console.warn(`⚠️ WARNING
Setting 'useContentHash' to 'false' in the production environment (specified by NODE_ENV environment variable) is not allowed!
Content hashes get added to the filenames regardless of setting useContentHash in 'shakapacker.yml' to false.
`)
}
Copy link

Choose a reason for hiding this comment

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

I just received this warning when deploying the Shakapacker v7 upgrade to production. Guessing from the warning, I would assume that the condition is incorrect. Shouldn't it state config.useContentHash === false?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for reporting

@justin808 fixed in #320

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.

Caching issues in Development since migrating to Shakapacker
3 participants