Skip to content

Commit a916bb6

Browse files
proxying public directory in development only
1 parent 1b9f3fa commit a916bb6

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/react-scripts/config/webpack.config.dev.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ if (publicPath === './') {
3131
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3232
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3333
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
34-
const publicUrl = publicPath.slice(0, -1);
35-
34+
const publicUrl = paths.servedPath.slice(0, -1) + '/assets';
3635
// Get environment variables to inject into our app.
3736
const env = getClientEnvironment(publicUrl === '.' ? '' : publicUrl);
3837
// This is the development configuration.

packages/react-scripts/config/webpackDevServer.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ignoredFiles = require('react-dev-utils/ignoredFiles');
1515
const url = require('url');
1616
const config = require('./webpack.config.dev');
1717
const paths = require('./paths');
18+
const express = require('express');
1819

1920
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
2021
const host = process.env.HOST || '0.0.0.0';
@@ -104,6 +105,10 @@ module.exports = function(proxy, allowedHost) {
104105
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
105106
app.use(noopServiceWorkerMiddleware(servedPathPathname));
106107
app.use(serveAppMiddleware(servedPathPathname));
108+
app.use(
109+
`${config.output.publicPath.slice(0, -1)}/assets`,
110+
express.static(paths.appPublic)
111+
);
107112
},
108113
};
109114
};

0 commit comments

Comments
 (0)