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

deep linking with contentBase gives a problematic side effect. #640

Closed
Foxandxss opened this issue Oct 7, 2016 · 8 comments
Closed

deep linking with contentBase gives a problematic side effect. #640

Foxandxss opened this issue Oct 7, 2016 · 8 comments

Comments

@Foxandxss
Copy link

Foxandxss commented Oct 7, 2016

I'm submitting a bug report

webpack and webpack-dev-server version:
webpack: 2 beta 25
webpack-dev-server: 2 beta 8

Please tell us about your environment:
macOS Sierra
Running via NPM script (AKA CLI)

Current behavior:

Loading a path (that is not root) directly (say localhost:8080/about) or refreshing it, will render the index.html as expected but the html webpack plugin will never inject the script tags with the bundle.

Expected/desired behavior:

Loading the localhost:8080/about should render the index.html and have all the scripts injected into it.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with a gist/jsbin of your webpack configuration. Be sure to specify how you are running the server.

If you want to reproduce it, clone this starter, install the dependencies, run npm start, go to /about and refresh it.

  • What is the expected behavior?

It should render the about page and not the index.html with the Loading... part.

I was unsure whether this is a bug at dev-server or html webpack plugin, but since the plugin is able to inject the stuff in the root path (or after a bundle) I think the bug relies on the dev server.

If you check the devServer config, you can see:

  config.devServer = {
    contentBase: './src/public',
    historyApiFallback: true,
    quiet: true,
    stats: 'minimal' // none (or false), errors-only, minimal, normal (or true) and verbose
  };

If I remove the contentBase (and move the index.html) it works.

I am using the contentBase to serve also the assets, so all the images can be loaded directly from there.

I could potentially remove the contentBase and fix things around but this is definitely a bug.

@SpaceK33z
Copy link
Member

I think the problem is that when using historyApiFallback, it will prefer the files from contentBase above the webpack in-memory files.

Previously this was not the case, I think it was changed in beta 8. Could you check if beta 7 works for you?

@Foxandxss
Copy link
Author

Doesn't work with beta 7 and according to #642 happens from beta 6

SpaceK33z pushed a commit that referenced this issue Oct 8, 2016
@SpaceK33z
Copy link
Member

SpaceK33z commented Oct 8, 2016

This is actually a very problematic issue. Every change here seems to break someone's setup, but we're getting there by adding more tests. For previous struggles, see #625, #627 and the "final" fix in cb1b32f.

I've added a failing test in the branch historyapifallback-struggles. If all tests succeed, this issue is solved. If anyone wants to take stab at it, please do. It is very important to not change the existing tests.

@cebor
Copy link

cebor commented Oct 10, 2016

A workaround is renaming the template for HtmlWebpackPlugin.

For example: index.html -> index.tmpl.html.

new HtmlWebpackPlugin({
  template: './src/index.tmpl.html',
  chunksSortMode: 'dependency'
}),

So the template does not get interpreted as index in the contentBase path.

SpaceK33z added a commit that referenced this issue Oct 11, 2016
Also, the test I wrote earlier was not correct.

Ref #640
@SpaceK33z
Copy link
Member

This should be fixed with 2.1.0-beta.9. Would appreciate a confirmation.

akirasosa added a commit to springboot-angular2-tutorial/angular2-app that referenced this issue Oct 12, 2016
@cebor
Copy link

cebor commented Oct 12, 2016

works for me, thanks!

@Foxandxss
Copy link
Author

Works for me too.

@WillooWisp
Copy link

Works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants