Skip to content

Commit

Permalink
Honor PUBLIC_URL in development
Browse files Browse the repository at this point in the history
  • Loading branch information
USER authored and EnoahNetzach committed Jan 31, 2017
1 parent 12f64d1 commit 511d1c4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
10 changes: 10 additions & 0 deletions packages/react-scripts/config/utils/ensureSlash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/');
if (hasSlash && !needsSlash) {
return path.substr(path, path.length - 1);
} else if (!hasSlash && needsSlash) {
return path + '/';
} else {
return path;
}
}
3 changes: 2 additions & 1 deletion packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var HtmlWebpackPlugin = require('html-webpack-plugin');
var CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
var WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
var ensureSlash = require('./utils/ensureSlash');
var getClientEnvironment = require('./env');
var paths = require('./paths');

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

Expand Down
12 changes: 1 addition & 11 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var ExtractTextPlugin = require('extract-text-webpack-plugin');
var ManifestPlugin = require('webpack-manifest-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
var url = require('url');
var ensureSlash = require('./utils/ensureSlash');
var paths = require('./paths');
var getClientEnvironment = require('./env');

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

function ensureSlash(path, needsSlash) {
var hasSlash = path.endsWith('/');
if (hasSlash && !needsSlash) {
return path.substr(path, path.length - 1);
} else if (!hasSlash && needsSlash) {
return path + '/';
} else {
return path;
}
}

// Webpack uses `publicPath` to determine where the app is being served from.
// It requires a trailing slash, or the file assets will get an incorrect path.
var publicPath = ensureSlash(paths.servedPath, true);
Expand Down
17 changes: 10 additions & 7 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ prompt(
}
}

var folders = [
'config',
path.join('config', 'jest'),
'scripts'
];

var files = [
path.join('config', 'env.js'),
path.join('config', 'paths.js'),
Expand All @@ -57,11 +51,20 @@ prompt(
path.join('config', 'webpack.config.prod.js'),
path.join('config', 'jest', 'cssTransform.js'),
path.join('config', 'jest', 'fileTransform.js'),
path.join('config', 'utils', 'ensureSlash.js'),
path.join('scripts', 'build.js'),
path.join('scripts', 'start.js'),
path.join('scripts', 'test.js')
path.join('scripts', 'test.js'),
];

var folders = files.reduce(function(prevFolders, file) {
var dirname = path.dirname(file);
if (prevFolders.indexOf(dirname) === -1) {
return prevFolders.concat(dirname);
}
return prevFolders;
}, []);

// Ensure that the app folder is clean and we won't override any files
folders.forEach(verifyAbsent);
files.forEach(verifyAbsent);
Expand Down

0 comments on commit 511d1c4

Please sign in to comment.