Skip to content

hashed file names #61

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

Closed
alexcroox opened this issue Jul 10, 2019 · 7 comments
Closed

hashed file names #61

alexcroox opened this issue Jul 10, 2019 · 7 comments

Comments

@alexcroox
Copy link

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

@maxmilton
Copy link
Contributor

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:

@alexcroox
Copy link
Author

Thank you and apologies for wasting your time. I missed that in the advanced section of the docs.

@maxmilton
Copy link
Contributor

It's all good. I know what it's like when you encounter a problem and just want to resolve it quickly.

Hope you were able to set your project up correctly :)

@jeduden
Copy link

jeduden commented Mar 3, 2020

Please note this that these suggestions don't work for the css file. See sveltejs/template#39

@crisward
Copy link

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.

@lukeed
Copy link
Member

lukeed commented Oct 21, 2020

CSS files will be hashed by default starting with 7.0 – see #136
This is because the CssWriter class will respect the underlying Rollup configuration.

@brgrz
Copy link

brgrz commented Apr 4, 2021

CSS files will be hashed by default starting with 7.0 – see #136
This is because the CssWriter class will respect the underlying Rollup configuration.

I am not seeing this in action. CSS doesn't get hashed even with Rollup configured to output hashed JS files.

Please provide details (Rollup config) on how this is supposed to work.

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

No branches or pull requests

6 participants