question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hashed file names

See original GitHub issue

First time using rollup so excuse the ignorance. Is it possible to export bundle.js/.css with hashed names so the browser doesn’t serve cached versions when I push to production? How would this work updating public/index.html

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
maxmiltoncommented, Jul 14, 2019

For general support questions you’re better off asking on sites like stackoverflow.com. Github issues are for reporting bugs or feature requests etc.

About your question, please read the rollup docs:

6reactions
criswardcommented, Oct 21, 2020

I realised this is a closed issue. But it was the first one that appeared when googling, so I thought I drop a solution here for anyone who finds it useful (including future me…)

I found that the css object passed to the css function holds a hashed filename the same as your entry file, including the hash, but with the css extension.

So the below would output index-[hash].js and index-[hash].css

//excerpt of rollup.js

export default {
	input: 'src/index.js',
	preserveEntrySignatures: false,
	output: {
		sourcemap: true,
		format: 'es',
		name: 'app',
		dir: 'build',
		entryFileNames: '[name]-[hash].js'
	},
	plugins: [
		svelte({
			// enable run-time checks when not in production
			css: css => {
				css.write(css.filename);
			}
    })
  ]
};

Also because I’m loading my css into a webcomponent, I parse the css filename by inspecting the module filename and swapping .js for .css

//index.js
let css_filename = import.meta.url.match(/[^\/]+\.js$/)[0].replace(/\.js$/,".css")

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta for more info on this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File Name Hashing: Creating a Hashed Directory Structure
File name hashing in the simplest terms can be defined as, creating a known and reproducible path, based on the name of the...
Read more >
Adding Hashes to Filenames - SurviveJS
Webpack's placeholders allow you to shape filenames and enable you to include hashes to them. The most valuable placeholders are [name] , [contenthash]...
Read more >
How to generate hashed file names of certificates
OpenSSL needs hashed file names of server certificates. The hashed file name consists of a hash obtained from OpenSSL, with a numerical extension...
Read more >
Generate unique hash from filename - Stack Overflow
Generating a unique hash from a file's filename is fairly simple. However... It should only contain numbers, and I want it to be...
Read more >
Dealing with hashed filenames - Davidsekar.com
Including hash value in filename helps the web browsers to identify the change in the file content or there by asset URL change,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found