Option not to include hash to file names
First of all thanks for this tool! It was really helpful for me to get started. I read all available how-to's and materials and really understand the purpose of this tool BUT... If this app is agnostic of the backend, and just produces static HTML/JS/CSS bundles there should be an option to leave filenames as is, as some ECM/CMS and other host systems has their own caching/versioning realization. Having different file names after each build mean need for manually deal with file published previously.
Having different file names after each build mean need for manually deal with file published previously.
Can you expand on how this creates the difficulty? What is the workflow like?
Hi! The workflow is following: CMS has it's own internal project-solution tracking system. Each web resource (html/css/js etc.) is saved in database and filename is used as alternative key for tracking project dependencies, or doing updates. If file name is changed the are two options for me: update each resource manually after each change or publish them as new resources. If I choose second option I'll have mess of unused resources in my project but they still be tracked as dependencies and will be moved to production environment after project import / export process.
If you're looking for a solution right now, there are definitely ugly ways to automate this using asset-manifest.json, which is a sort of mapping from the original names to the hashed names.
Thanks. As for now I choose eject and modify webpack config in 3 or 5 places. That's why I'm proposing a centralized option suitable for config or doing fork
Feels like a very specific use case. Most users benefit from cache busting naming convention. Being able to set far future expire headers on static assets speeds loading up of the site for revisits. It sounds like you can read the asset-manifest and feed your DB with it.
Unfortunately it's not specific in MS world. In most cases we have to include static files to Visual Studio projects to be able to publish them. There is specific but it's normal case here.
If you're looking for a solution right now, there are definitely ugly ways to automate this using asset-manifest.json, which is a sort of mapping from the original names to the hashed names.
This does sound like the right way to me. And you could right an automated script that reads it, does something, and even share that script between projects.
Sorry but I can't understand how can it help me if build command will generate index.html with references to files with hashes?
Hm, I was thinking more that you could feed your cms with it. Is there really no way to specify renamed resources, or to remove old resources from the project? Since the main issue is the "mess of unused resources".
If that's not an option, then ejecting is probably the best bet right now. You could do find/replace and rename using the asset manifest, but thinking about it now it might break source maps.
Whilst this is something which is rare, there are some use cases for this. For my company, we develop web apps to be served on a survey platform. This platform allows us to upload the .js and .css files onto their site, but the relevant contents of the index.html has to be copy/pasted into a question form on this platform (ie, a HTML block). Currently hashing means every time we do a change to the code, we not only have to upload the bundles, but then manually go to the html block, copy/paste the new name of the bundle and resave that page. Being a manual process, this is error-prone as well as plain slow.
Being able to turn hashing off would save a lot of pain and potential errors for this use-case. Obviously we can just eject, but that is meant to be a last resort.
I'm currently in this situation where the hashing in filenames causes issues. Whilst ejecting is a solution, it seems like a broken solution.
@WolfieZero, I did a fork and made some changes in react scripts package to get static names after build. It may be not best way but it is still much better then doing eject. Please refer to this manual: https://auth0.com/blog/how-to-configure-create-react-app/. As far as I understand it is supported approach
@FixRM Awesome, will take a look at. Thanks!
@WolfieZero You can try mine but it uses TypeScript: https://github.com/FixRM/create-react-app-typescript-static
Why don't you add query hashes instead of hashing file names?
If you generate your HTML in that way everyone should be satisfied.
@Havret the downside to query strings is intermediate proxies (such as CDNs) will often ignore the query string by default.
I am needing this to (bundles without hashes). I dont think it to be so hard to implement. And should be like and option (by default include the hashes)
Something that I was able to do with React Rewired (https://github.com/timarney/react-app-rewired). I will say that if you are really overriding a lot in the future it might be worth ejecting.
// config-overrides.js
module.exports = {
webpack: function(config, env) {
if (env === "production") {
//JS Overrides
config.output.filename = 'static/js/[name].js';
config.output.chunkFilename = 'static/js/[name].chunk.js';
//CSS Overrides
config.plugins[4].filename = 'static/css/[name].css';
//Media and Assets Overrides
config.module.rules[1].oneOf[0].options.name = 'static/media/[name].[ext]';
config.module.rules[1].oneOf[3].options.name = 'static/media/[name].[ext]';
/**
* If the media/assets public path differs on the server
*
* config.module.rules[1].oneOf[0].options.name = 'static/media/[name].[ext]';
* config.module.rules[1].oneOf[0].options.publicPath = '/public/assets/';
* config.module.rules[1].oneOf[3].options.name = 'static/media/[name].[ext]';
* config.module.rules[1].oneOf[3].options.publicPath = '/public/assets/';
*/
}
return config;
}
};
This should take care of the hashes, mapping, and media/asset. Sadly with the way plugins are implemented in an array, I have to use fixed indexes. Also, if you do end up adding more plugins it could mess with those fixed indexes.
We serve our react app from Django staticfiles, and we use Django's builtin CachedStaticfFilesStorage, which itself takes care of hashing all static assets etc, so we end up with a doubly hashed bundle :-/ This is really a PITA and I really don't understand why there's no simple option to deactivate hashing in create-react-app. Really, why force peoples to go through all sorts of hoops just to make things work for their own use case ?
I'm also having issues with this, here is the scenario:
The app is hosted on Netlify. Since it's a SPA, redirect rules are set to redirect any route to index.html.
First access to app caches the current bundle name. If a new deployment/build is done, a new bundle name is generated.
In a second access, the browser still requests old bundle name generated on first build. Server doesn't find requested js file, so redirect rules apply and index.html is served as a js file.
Result is a blank page and the following error on console since it tries to read js but server delivers a HTML file:
Unexpected token <