Skip to content

Commit 511d1c4

Browse files
USEREnoahNetzach
USER
authored andcommitted
Honor PUBLIC_URL in development
1 parent 12f64d1 commit 511d1c4

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = function ensureSlash(path, needsSlash) {
2+
var hasSlash = path.endsWith('/');
3+
if (hasSlash && !needsSlash) {
4+
return path.substr(path, path.length - 1);
5+
} else if (!hasSlash && needsSlash) {
6+
return path + '/';
7+
} else {
8+
return path;
9+
}
10+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
1515
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
1616
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1717
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
18+
var ensureSlash = require('./utils/ensureSlash');
1819
var getClientEnvironment = require('./env');
1920
var paths = require('./paths');
2021

@@ -29,7 +30,7 @@ var publicPath = '/';
2930
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3031
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3132
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
32-
var publicUrl = '';
33+
var publicUrl = ensureSlash(paths.servedPath, false);
3334
// Get environment variables to inject into our app.
3435
var env = getClientEnvironment(publicUrl);
3536

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin');
1616
var ManifestPlugin = require('webpack-manifest-plugin');
1717
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
1818
var url = require('url');
19+
var ensureSlash = require('./utils/ensureSlash');
1920
var paths = require('./paths');
2021
var getClientEnvironment = require('./env');
2122

@@ -24,17 +25,6 @@ var getClientEnvironment = require('./env');
2425
var path = require('path');
2526
// @remove-on-eject-end
2627

27-
function ensureSlash(path, needsSlash) {
28-
var hasSlash = path.endsWith('/');
29-
if (hasSlash && !needsSlash) {
30-
return path.substr(path, path.length - 1);
31-
} else if (!hasSlash && needsSlash) {
32-
return path + '/';
33-
} else {
34-
return path;
35-
}
36-
}
37-
3828
// Webpack uses `publicPath` to determine where the app is being served from.
3929
// It requires a trailing slash, or the file assets will get an incorrect path.
4030
var publicPath = ensureSlash(paths.servedPath, true);

packages/react-scripts/scripts/eject.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ prompt(
4343
}
4444
}
4545

46-
var folders = [
47-
'config',
48-
path.join('config', 'jest'),
49-
'scripts'
50-
];
51-
5246
var files = [
5347
path.join('config', 'env.js'),
5448
path.join('config', 'paths.js'),
@@ -57,11 +51,20 @@ prompt(
5751
path.join('config', 'webpack.config.prod.js'),
5852
path.join('config', 'jest', 'cssTransform.js'),
5953
path.join('config', 'jest', 'fileTransform.js'),
54+
path.join('config', 'utils', 'ensureSlash.js'),
6055
path.join('scripts', 'build.js'),
6156
path.join('scripts', 'start.js'),
62-
path.join('scripts', 'test.js')
57+
path.join('scripts', 'test.js'),
6358
];
6459

60+
var folders = files.reduce(function(prevFolders, file) {
61+
var dirname = path.dirname(file);
62+
if (prevFolders.indexOf(dirname) === -1) {
63+
return prevFolders.concat(dirname);
64+
}
65+
return prevFolders;
66+
}, []);
67+
6568
// Ensure that the app folder is clean and we won't override any files
6669
folders.forEach(verifyAbsent);
6770
files.forEach(verifyAbsent);

0 commit comments

Comments
 (0)