Vite 构建永远挂起

Ste*_*ves 15 build freeze exit vite

当我运行时vite buildnpm run build构建执行时没有错误。

我明白了built in 4661ms.,但这个过程永远不会结束。它只是挂着。

如何让进程结束并退出?

for*_*tso 7

您可以通过挂钩buildEndcloseBundle事件轻松退出 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\n
Run Code Online (Sandbox Code Playgroud)\n

将插件导入到你的vite.config.ts

\n
// 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()],\n
Run Code Online (Sandbox Code Playgroud)\n

JS 文件也是如此,只需切换扩展名即可。

\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
\n


use*_*037 1

听起来像是vite在观察变化。

如果您已build.watch在 中进行了配置vite.config.ts,则运行时vite build将监视项目,而无需显式指定--watch参数。