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

Disable implicit serving of the source files #551

Merged
merged 2 commits into from
Sep 2, 2016
Merged

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Sep 2, 2016

Migration Instructions

Paths like /src/somefile.png used to be served in development, but only by accident. They never worked in production builds. Since 0.4.0, we don’t serve static files by default in development anymore either. This removes a dangerous inconsistency that we never intentionally supported.

If you need a static file to be part for the build, import it from JavaScript and you will get its filename. This ensures it gets included into the production build as well, and its filename contains the content hash.

If you used static files with <link href>, read this new guide on how to make sure these files get included into the builds. For example, you can replace <link href="/src/favicons/favicon-32.png"> with <link href="./src/favicons/favicon-32.png">, and then Webpack will recognize it and include it into the build.

If you referenced some other files from index.html, please file an issue to discuss your use case. In the meantime, you can serve them from a separate static server until your use case is supported.


Fixes #503 (it was never intentionally supported).
Supersedes #226 (I think there is not enough proof that this feature is necessary after #428).
Documents #428.

I understand this will be somewhat controversial because people might rely on this, but if they do, their production builds are already broken right now. This brings our features to consistency and documents the escape hatch that I believe removes the need for #226.

Justification in the comment:

 +    // By default WebpackDevServer also serves files from the current directory.
 +    // This might be useful in legacy apps. However we already encourage people
 +    // to use Webpack for importing assets in the code, so we don't need to
 +    // additionally serve files by their filenames. Otherwise, even if it
 +    // works in development, those files will be missing in production, unless
 +    // we explicitly copy them. But even if we copy the all the files into
 +    // the build output (which doesn't seem to be wise because it may contain
 +    // private information such as files with API keys, for example), we would
 +    // still have a problem. Since the filenames would be the same every time,
 +    // browsers would cache their content, and updating file content would not
 +    // work correctly. This is easily solved by importing assets through Webpack
 +    // because if it can then append content hashes to filenames in production,
 +    // just like it does for JS and CSS. And because we configured "html" loader
 +    // to be used for HTML files, even <link href="./src/something.png"> would
 +    // get resolved correctly by Webpack and handled both in development and
 +    // in production without actually serving it by that path.

@gaearon gaearon added this to the 0.4.0 milestone Sep 2, 2016
@ghost ghost added the CLA Signed label Sep 2, 2016
@gaearon gaearon merged commit f1c9584 into master Sep 2, 2016
@gaearon gaearon deleted the disable-contentbase branch September 2, 2016 19:35
stayradiated pushed a commit to stayradiated/create-react-app that referenced this pull request Sep 7, 2016
* Disable contentBase in development

* Document facebook#428
feiqitian pushed a commit to feiqitian/create-react-app that referenced this pull request Oct 25, 2016
* Disable contentBase in development

* Document facebook#428
@lock lock bot locked and limited conversation to collaborators Jan 22, 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.

Serve assets from public/ instead of .
1 participant