[英]PDF file gets exlcluded from build files Vite
My package.json looks like this:我的 package.json 看起来像这样:
{
"name": "portfolio",
"version": "1.0.0",
"author": "Udbhav Prasad",
"license": "MIT",
"engines": {
"node": "14.x"
},
"files": [
"dist/UdbhavPrasad-Resume.pdf"
],
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "vite preview"
},
"dependencies": {
"three": "^0.128.0",
"vite": "^2.3.3"
}
}
But when I build it, in /dist is excludes the resume and wont serve it when GET request is sent但是当我构建它时,在 /dist 中排除了简历,并且在发送 GET 请求时不会提供它
Thank you谢谢
Well the easiest way to get your pdf file built is simply to place it at the root of your /public
folder.构建 pdf 文件的最简单方法是将其放在
/public
文件夹的根目录下。 That way it would appear at the root of your /dist
folder once built.这样,一旦构建,它就会出现在
/dist
文件夹的根目录中。
See https://vitejs.dev/guide/assets.html#the-public-directory for more info.有关详细信息,请参阅https://vitejs.dev/guide/assets.html#the-public-directory 。
Suppose your HTML look like this:假设您的 HTML 看起来像这样:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF</title>
</head>
<body>
<a download="" href="./pdf/UdbhavPrasad-Resume.pdf" class="cv-download">Download CV</a>
<script type="module" src="./js/main.js"></script>
</body>
</html>
Then in your main.js file, you can get the URL with ?url
.然后在你的 main.js 文件中,你可以得到 URL 和
?url
。 then set the URL to your preferred place.然后将 URL 设置为您喜欢的位置。 That's it.
而已。
import pdfURL from "../pdf/UdbhavPrasad-Resume.pdf?url";
document.querySelector(".cv-download").href = pdfURL;
For more information read this https://vitejs.dev/guide/assets.html有关更多信息,请阅读此https://vitejs.dev/guide/assets.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.