SvelteKit / Vite.js 如何链接大型静态内容

huangapple go评论67阅读模式
英文:

SveleteKit / Vite.js how to link in large static content

问题

I'm using Svelte to drive some tools I'm using internally. I found it easy to get started with SvelteKit, but I don't really want to do a deep dive into how it works, and the documentation is opaque.

我在内部使用Svelte驱动一些工具。我发现使用SvelteKit很容易入门,但我不太想深入了解它的工作原理,而且文档不太清晰。

I have several (huge) directories of static content that I want to serve from within my app. I found that it worked if I simply symlinked my content directories into project/static/symlink and I could get at them, using 'npm run dev' to start the server.

我有几个(很大的)静态内容目录,我想从我的应用程序中提供。我发现如果我简单地将我的内容目录创建符号链接到project/static/symlink中,然后使用'npm run dev'启动服务器,它就能正常工作。

But now I'm running into problems. There are so many files I'm hitting the system inotify limits, and I don't really want them watched by SvelteKit anyway.

但现在我遇到了问题。文件太多,我达到了系统inotify的限制,而且我其实也不希望SvelteKit监视它们。

a) How do I serve basic static content without any Vite or Svelte bells and whistles?
a) 如何提供基本的静态内容,而不需要使用Vite或Svelte的高级功能?

b) 'npm run dev' starts up slow. How do I build and run the site (WITHOUT copying all of the above static content) for regular running? 'npm build' is taking forever and I'm guessing it's paging through all that stuff.
b) 'npm run dev'启动速度较慢。如何构建并运行站点(而不复制所有上述的静态内容)以进行常规运行?'npm build'花费了很长时间,我猜测它正在遍历所有这些内容。

英文:

I'm using svelete to drive some tools I'm using internally. I found it easy to get started with sveletekit, but I don't really want to do a deep dive into how it works, and the documentation is opaque.

I have a several (huge) directories of static content that I want to serve from within my app. I found that it worked if I simply symlined my content directories into project/static/symlink and I could get at them, using 'npm run dev' to start the server.

But now I'm running into problems. There are so many files I'm hitting the system inotify limits, and I don't really want them watched by sveletekit anyway.

a) How do I serve basic static content without any vite of svelte bells and whistles?
b) 'npm run dev' starts up slow. How do I build and run the site (WITHOUT copying all of the above static content) for regular running? 'npm build' is taking forever and I'm guessing it's paging through all that stuff.

答案1

得分: 1

你可以将以下内容添加到你的 vite.config.js 中,以排除静态资产的监视:

server: {
    watch: {
      ignored: ["/static/**"],
    },
  },

我不认为有办法缩短构建时间,因为 SvelteKit 必须将所有资产复制到构建文件夹中,你可以忽略这些文件以进行构建,并编写一个脚本来执行此操作(或将其符号链接到构建文件夹),但这对于云部署来说并不是真正可行的解决方案。

英文:

You can add the following to your vite.config.js to exclude the static assets from being watched

server: {
    watch: {
      ignored: ["/static/**"],
    },
  },

I don't see a way around the long build times because sveltekit has to copy all the assets into the build folder, you can ignore those files for build and have a script that does it for you (or symlinks it to the build folder) but that son't really work for cloud deployments

huangapple
  • 本文由 发表于 2023年6月29日 22:38:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定