您可以通过挂钩buildEnd和closeBundle事件轻松退出 Vite。
\n定义一个插件如下:
\n// file vite-plugin-close.ts\n\nexport default function ClosePlugin() {\n return {\n name: \'ClosePlugin\', // required, will show up in warnings and errors\n\n // use this to catch errors when building\n buildEnd(error) {\n if(error) {\n console.error(\'Error bundling\')\n console.error(error)\n process.exit(1)\n } else {\n console.log(\'Build ended\')\n }\n },\n\n // use this to catch the end of a build without errors\n closeBundle(id) {\n console.log(\'Bundle closed\')\n process.exit(0)\n },\n }\n}\n\nRun Code Online (Sandbox Code Playgroud)\n将插件导入到你的vite.config.ts
// file vite.config.ts\n\nimport ClosePlugin from \'./vite-plugin-close.ts\'\n...\n\n// place the plugin in the *vite* plugins section\n// NOT the rollupOptions.plugins section\n plugins: [ClosePlugin()],\nRun Code Online (Sandbox Code Playgroud)\nJS 文件也是如此,只需切换扩展名即可。
\n\n\n\xe2\x9c\x93 已转换 3662 个模块。\ndist/bundle/cli.js 8,825.66 kB\n捆绑包已关闭\n(base) \xe2\x9e\x9c cli git:(main) \xe2\x9c\x97
\n
听起来像是vite在观察变化。
如果您已build.watch在 中进行了配置vite.config.ts,则运行时vite build将监视项目,而无需显式指定--watch参数。
| 归档时间: |
|
| 查看次数: |
5163 次 |
| 最近记录: |