lisonge / vite-plugin-monkey

A vite plugin server and build your.user.js for userscript engine like Tampermonkey, Violentmonkey, Greasemonkey, ScriptCat
MIT License
1.31k stars 70 forks source link

是否有方法可以使多个UserScript在同一目录下开发? #82

Closed LinLin00000000 closed 1 year ago

LinLin00000000 commented 1 year ago

我不想使用 monorepo 那一套东西,我想直接在单个目录(比如“src”)中开发多个脚本,vite配置大概像这样 image 不想引入很多资源、包做个大工程,只想做点小东西,有没有方便的方法实现这样简单便捷的开发方式呢?

lisonge commented 1 year ago

在同一目录下创建多个 vite.config.xx.ts 即可

vite.config.script1.ts

vite --config vite.config.script1.ts 

vite.config.script2.ts

vite --config vite.config.script2.ts 

vite.config.script3.ts

vite --config vite.config.script3.ts 
LinLin00000000 commented 1 year ago

有一个问题,构建多个script时,后一个的构建产物会覆盖前一个,即使 build.fileName 不一样。 并行构建的话有时可以顺利构建多个,有时就只剩一个文件了😢

lisonge commented 1 year ago

viteConfig.build.emptyOutDir=false

LinLin00000000 commented 1 year ago

又遇到一个问题,vite preview 时会进行脚本安装,但当 dist 目录下有多个 userscript 时只会安装其中一个。

我试着修复了一下。 #83

LinLin00000000 commented 1 year ago

感谢作者的耐心解答和光速回复,问题已解决。

我直接调用 vite 的 build、preview API 实现了一个简单的构建脚本,可以方便我的小脚本快速开发😊 https://github.com/LinLin00000000/L-UserScript/blob/main/index.js

uulll commented 4 months ago

请问,通过vite.config.script1.ts配置之后,是通过npm run build 命令打包还是什么呢。 image 这是我的目录结构,报错了:RollupError: Could not resolve entry module "index.html".

lisonge commented 4 months ago

https://cn.vitejs.dev/guide/cli.html

lisonge commented 4 months ago
vite build --config vite.config.script1.ts 
lisonge commented 4 months ago

--config

uulll commented 4 months ago

非常感谢!!!

uulll commented 4 months ago

大佬,在请教一下,有没有类似于 vite build --config * 之类的语法,希望能将多个脚本一起打包

lisonge commented 4 months ago
vite build --config vite.config1.ts && vite build --config vite.config2.ts
uulll commented 4 months ago

看来只能用批处理做了。 分享一下:for /r %i in (vite.config.*.js) do ( npx vite build -c %i )