-
-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Add PUBLIC_URL env variable for advanced use (#937)
#1504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'); | ||
|
|
||
|
|
@@ -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); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import React from 'react' | ||
|
|
||
| export default () => ( | ||
| <span id="feature-public-url">{process.env.PUBLIC_URL}.</span> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import PublicUrl from './PublicUrl'; | ||
|
|
||
| describe('PUBLIC_URL', () => { | ||
| it('renders without crashing', () => { | ||
| const div = document.createElement('div'); | ||
| ReactDOM.render(<PublicUrl />, div); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine to give these more verbose names if that would make it easier to understand what they represent. Right now it's not super obvious to me what the difference is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and just removed the third variable as it was unnecessary.
publicUrlandservedPathseem straightforward to me (now thatservedUrlis gone).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer different names still?