【问题标题】:Running parcel bundler from command line doesn't stop the process从命令行运行包裹捆绑器不会停止该过程
【发布时间】:2019-08-23 16:07:07
【问题描述】:

我有一个运行 parcel bundler 的简单 JS 文件:

const Bundler = require('parcel-bundler');
(async () => {
  const bundler = new Bundler('./src/index.html', {}); // options omitted for simplicity
  await bundler.bundle();
})();

我从 CLI 运行它:

node ./build.js

虽然捆绑器工作正常并在 dist 文件夹中创建捆绑文件,但该过程永远不会退出,而是保持在异步循环中。

我尝试添加then 回调或使用return,但没有任何帮助。 使用 process.exit() 当然会停止这个过程,但也会限制我在 CI 中链接这个命令,这就是整个目的。

我做错了什么?

【问题讨论】:

  • 您是否尝试调查bundler.on("buildEnd", ...) 或类似事件?他们会被叫到吗?
  • 是的,构建正常结束,我收到Built in ... 消息。此外,如果我使用带有控制台日志的回调,我可以看到它被打印出来。但是节点进程永远不会结束。

标签: javascript node.js async-await bundler parceljs


【解决方案1】:

您需要在选项中设置watch: false,让 Parcel 知道它不应该观看,而只构建一次。

默认选项是watch: true,因此每当您更改文件中的某些内容时,Parcel 都会识别更改并重新构建您的应用程序。

【讨论】:

    猜你喜欢
    • 2021-02-06
    • 2018-06-16
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多