[英]Vue 2 with Vue CLI - How to make src/static static so I can use images that are in there?
I'm trying to package my Vue CLI app to package src/static/xyz.png
such that I can reference it as /static/xyz.png
.我正在尝试将我的 Vue CLI 应用程序 package 到 package
src/static/xyz.png
以便我可以将其引用为/static/xyz.png
。
The Vue docs don't really show how to do this. Vue 文档并没有真正展示如何做到这一点。 I need a
vue.config.js
but between here:我需要一个
vue.config.js
但在这之间:
https://cli.vuejs.org/guide/webpack.html https://cli.vuejs.org/guide/webpack.html
and here:和这里:
https://cli.vuejs.org/guide/html-and-static-assets.html#htmlhttps://cli.vuejs.org/guide/html-and-static-assets.html#html
I can't figure out what I need to do.我不知道我需要做什么。 Any ideas?
有任何想法吗? I've tried lots of webpack stuff but don't know webpack well enough, evidently...
我已经尝试了很多 webpack 的东西,但不太了解 webpack,显然......
In Vue CLI projects, files under public/
are automatically bundled as static assets , so you don't need a custom config for this.在 Vue CLI 项目中,
public/
下的文件会自动捆绑为 static 资产,因此您不需要为此进行自定义配置。 Your image should be stored in:您的图像应存储在:
<projectRoot>/public/static/xyz.png
Then you'd reference them in your markup like this:然后你会在你的标记中引用它们,如下所示:
<img src="/static/xyz.png">
Note that these static assets are not run through Webpack, so they won't be optimized (ie, the image file size might be unnecessarily large).请注意,这些 static 资产不是通过 Webpack 运行的,因此它们不会被优化(即,图像文件大小可能不必要地大)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.