Full-Stack React Projects
上QQ阅读APP看书,第一时间看更新

Serving static files from the dist folder

Webpack will compile client-side code in both development and production mode, then place the bundled files in the dist folder. To make these static files available on requests from the client side, we will add the following code in server.js to serve static files from dist/folder.

mern-simplesetup/server/server.js:

import path from 'path'
const CURRENT_WORKING_DIR = process.cwd()
app.use('/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))