How to use Express with Parceljs middleware in Production


I am using Parcel middleware with express as explained here:

When I run this in production I don’t want hot-module replacement to be turned on.

How can I set this up so that it works in dev with HMR and in prod without HMR? Essentially I don’t know how to use the build mode with this middleware:

Should I only use parcel-bundler if this is in dev and use static config if this is in prod?

Adding sample code for reference:

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

// Listen on port 8080


You can set options for the bundler as so

const bundlerOptions = { production: process.env.NODE_ENV === 'production' };
const bundler        = new Bundler( filePath, bundlerOptions );

This will disable HMR as described in the parcel documentation

Answered By – cs.jasonbrooks

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published