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

Undesirable behaviour of webpack dev server using CLI generated config #985

Open
chrisckc opened this issue Nov 23, 2018 · 0 comments
Open

Comments

@chrisckc
Copy link
Contributor

chrisckc commented Nov 23, 2018

I'm submitting a bug report
I'm submitting a feature request

The webpack dev server setting: 'contentBase' sets the path from where static content should be served from.
https://webpack.js.org/configuration/dev-server/#devserver-contentbase

This is set in 2 places in the CLI generated config:
run.ts line 17:

contentBase: config.output.path,

and also in the webback.config

devServer: {
    contentBase: outDir,
    // serve index.html for all 404 (required for push-state)
    historyApiFallback: true
  },

This causes the dev server to also serve files from the 'dist' directory in addition to the dynamically generated files from the webpack build which are served from a temporary in-memory virtual filesystem. (au run launches the webpack dev server, no files are outputted to the 'dist' dir)

This can cause confusion if files are left over in the 'dist' dir from previous production builds (au build --env prod). Newcomers to webpack will probably not realise that this can happen and the behaviour seems counter intuitive as the 'dist' dir is intended as purely an output dir for production builds.

The 'dist' build dir should not really be available as an input dir for serving via the dev server. I have however seen some implementations in other projects/frameworks that rely on this behaviour as they either store static files in the 'dist' dir or use a separate script outside of webpack to copy static assets over to the 'dist' dir. In that case the behaviour would be required to be able to access those files via the dev server.

By using the CopyWebpackPlugin to copy static assets as in the CLI generated webpack config, the static assets are copied into the temporary in-memory filesystem used by the dev server so are available to be served. This removes the need for also serving files from the 'dist' dir. and creates a more consistent dev/prod setup.

If contentBase is not set, as per the webpack docs, the dev server defaults to serving files from the current working dir, which means you can do this to retrieve the contents of package.json
http://localhost:8080/package.json or any other servable file type.

Setting contentBase to false disables the static file serving altogether which should be the case here.

Current behavior:

Left over files in the 'dist' dir can be served when using au run which uses the webpack dev server.
Files from the dev build are served in preference to the files in 'dist' , but this can still cause unexpected issues or surprises in some circumstances.

  • What is the expected behavior?

Left over files in the 'dist' dir are not be served as it is purely an output dir in the CLI generated project template.

  • What is the motivation / use case for changing the behavior?

Avoid issues.

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

1 participant