Skip to content
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

Reads CDN_URL to populate webpack publicPath #694

Closed
wants to merge 1 commit into from

Conversation

SeeThruHead
Copy link

closes #647

Previously we only allowed settings the pathname via the "homepage" key
in package.json

Allows user to configure the full base URL via a $CDN_URL env
variable

Development has the same behaviour.

@ghost
Copy link

ghost commented Sep 21, 2016

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ghost
Copy link

ghost commented Sep 21, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ghost ghost added the CLA Signed label Sep 21, 2016
@@ -25,14 +25,21 @@ if (env['process.env.NODE_ENV'] !== '"production"') {
}

// We use "homepage" field to infer "public path" at which the app is served.
// You may also use the environment variable CDN_URL to set the homepage to an absolute url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment now looks a bit messy. Can you please format it so that sentences start with capital letters, end with newlines, and the complete comment doesn't look like it's written by two different people?

@@ -64,7 +83,7 @@ module.exports = {
// containing code from all our entry points, and the Webpack runtime.
filename: 'static/js/bundle.js',
// In development, we always serve from the root. This makes config easier.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change directly contradicts the comment above it. Please be sure to read the comments above the code you are changing, and keep them in sync.

@@ -64,7 +83,7 @@ module.exports = {
// containing code from all our entry points, and the Webpack runtime.
filename: 'static/js/bundle.js',
// In development, we always serve from the root. This makes config easier.
publicPath: '/'
publicPath: publicPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this change is necessary. This would break the development workflow because it would request files from CDN instead of the local server. Is this change in the development configuration intentional?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes people are going to serve both index.html and the js bundle at different hosts in dev just like they would do in production.

For most of my local dev I'm loading a react app into a rails view, (not using cra's generated html) during local dev and production. This makes that kind of thing possible without changing how it works for anyone not using $CDN_URL.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe CDN_URL should always be webpacks host + port, in dev?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should file a separate issue for discussing Rails development workflow. I’m not familiar with it so it’s not obvious to me how this works.

Copy link
Author

@SeeThruHead SeeThruHead Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove this (removes most of the benefit I would get from this pr :( but I understand if it's not suitable here.)

Just want to point out that it's not rails specific really. It's the only way to load your react bundle into a host other than the same host that's serving the js files, Currently we are locked down to CRA serving the html.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s discuss more in the issue then so that I can get a better understanding of what you wanted. If you could guide me through your development workflow, what’s running on what port, and how you intend to use CDN_URL, etc, that would help.

} else {
// no homepage
console.log('To override this, specify the ' + chalk.green('homepage') + ' in your ' + chalk.cyan('package.json') + '.');
console.log();
console.log('Alternatively, you may change the absolute URL for all files by setting a CDN_URL environment variable');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these logs are too noisy. Let’s remove them as most users won’t need them. Those who need them will look for “CDN” in “Usage Guide”.

closes facebook#647

Previously we only allowed settings the pathname via the "homepage" key
in package.json

Allows user to configure the full base URL via a $CDN_URL env
variable

Development has the same behaviour.
@ghost ghost added the CLA Signed label Sep 21, 2016
@gaearon gaearon added this to the 1.0.0 milestone Sep 22, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 22, 2016

I’m going to make significant changes in #703 but I think this PR could complement those pretty nice by allowing PUBLIC_URL to be set from outside. I will ping you after #703 lands so that you could rebase on top of that.

@ghost ghost added the CLA Signed label Sep 22, 2016
@gaearon
Copy link
Contributor

gaearon commented Sep 30, 2016

#703 has landed.

Can you please send a new PR on top of it that honors PUBLIC_URL environment variable?

This would make it consistent with how the code already works (that’s the name of the variable we expose).

Thanks!

@Timer
Copy link
Contributor

Timer commented Feb 11, 2017

Hi there! react-scripts v0.9.0 was just released which adds support for specifying a CDN url. You may read how to configure it here.

Please test it and don't hesitate to reach out if this doesn't solve your specific use case!

@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Applications served from cdn on different host
5 participants