4

I'm using Vuejs in a new project and I've added some images to the assets folder. I need an image to be referenceable also in public/index.html, but when I build the project the resulting filename includes an hash.

For instance I've src/assets/logo.svg and after build I've dist/img/logo.e80b121e.svg, but I want dist/img/logo.svg

Is there a way to remove the hash only for a specific file? I need the hash in the other assets. I'm configuring webpack with vue.config.js.

2 Answers 2

1

If you're using the webpack config vue cli generated four you if you move your asset in the static folder it will not get the hash.

Items from assets are getting hashed.

Sign up to request clarification or add additional context in comments.

3 Comments

I reference the image also in a lot of vue components and I want to avoid to manually handle the path like in the documentation: cli.vuejs.org/guide/…
although that's the canonical way of including it, just doing /static/path/to/image will also work. Ofc, this depends on the value of <base href.
So I ended up setting <base href="<%= BASE_URL %>"> in index.html, putting the file in the /public/ folder and replacing the image path with ./logo.svg in the components
1

You need to get out the assets files from the entry, assuming that you has chunckhash configured (something like this: output: {filename: "[name].[chunkhash].js"}). You could copy directly from source and add the assets to index.html using some of this webpack plugins:

example:

plugins: [ new HtmlWebpackExternalsPlugin({ externals: [ { module: "@fortawesome/fontawesome-pro", entry: "css/all.css", }, ], }), new CopyWebpackPlugin([ { from: "./node_modules/@fortawesome/fontawesome-pro/webfonts", to: "./vendor/@fortawesome/fontawesome-pro/webfonts/", }, ]), ] 

2 Comments

I've used CopyWebpackPlugin and now there are both logo.cd5607bc.svg and logo.svg, how can I have only logo.svg?
Removing it from the entry ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.