【发布时间】:2019-08-06 12:50:31
【问题描述】:
我正在使用带有 express 的 Parcel 中间件,如下所述:https://parceljs.org/api.html#middleware
当我在生产中运行它时,我不想打开热模块更换。
如何设置它以使其在带有 HMR 的 dev 中和在没有 HMR 的 prod 中工作?基本上我不知道如何在这个中间件上使用build 模式:https://parceljs.org/production.html#%E2%9C%A8-production
如果这是在 dev 中,我应该只使用 parcel-bundler,如果这是在 prod 中,我应该使用 static 配置吗?
添加示例代码供参考:
const Bundler = require('parcel-bundler');
const app = require('express')();
const file = 'index.html'; // Pass an absolute path to the entrypoint here
const options = {}; // See options section of api docs, for the possibilities
// Initialize a new bundler using a file and options
const bundler = new Bundler(file, options);
// Let express use the bundler middleware, this will let Parcel handle every request over your express server
app.use(bundler.middleware());
// Listen on port 8080
app.listen(8080);
【问题讨论】: