shellscape / koa-webpack

Development and Hot Reload Middleware for Koa2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect check for publicPath

joacim-boive opened this issue · comments

  • Node Version: 10.9.0
  • NPM Version: 6.4.1
  • koa Version: 2.6.2
  • koa-wepback Version: 5.1.1

Expected Behavior

Allow to have configured publicPath in the Webpack config to an empty string: publicPath: '';

Actual Behavior

It throws:
"koa-webpack: publicPath must be set on dev options, or in a compiler's output configuration."

How can we reproduce the behavior?

Configure webpack to have publicPath to an empty string.

The fix would be to do something like this in lib/index.js

if (!options.devMiddleware.publicPath) {
    const { publicPath } = compiler.options.output;

    if (typeof publicPath === 'undefined') {
      throw new Error(
        "koa-webpack: publicPath must be set on `dev` options, or in a compiler's `output` configuration."
      );
    }

    options.devMiddleware.publicPath = publicPath;
  }

Interesting, don't think I've seen a use-case for setting publicPath to anything falsy, since webpack handles falsy values internally and defaults to ''. Not sure what your setup looks like, but it's almost a certainty that using an empty string in this case is not what you're actually after. Happy to help you solve that, but allowing users to set publicPath to an empty string (the default value) doesn't make much sense for this package.

It worked to use publicPath: '/' in my case as well and that solves it here as well.

Thanks anyway. 👍