- Full-Stack React Projects
- Shama Hoque
- 67字
- 2021-06-25 21:45:00
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')))