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

解决无法直接访问根目录(如:http://localhost:9000/)问题 #357

Open
zwlijun opened this issue Feb 26, 2019 · 0 comments
Open

Comments

@zwlijun
Copy link

zwlijun commented Feb 26, 2019

环境: Node + Express + VUE-SSR + ...
发现:在development模式下,直接访问 http://localhost:9000/ 时,会直接输出模板生成index.html文件,用production模式下访问正常。
解决:查看 webpack-dev-middleware 源码,发现如果options对象中的index没有配置或为true时会指向index.html,所以需要在setup-dev-server.js 定义webpack-dev-middleware时的options对象参数中增加一个index属性,值为 “/” 即可解决。

  // dev middleware
  const clientCompiler = webpack(clientConfig)
  const devMiddleware = require('webpack-dev-middleware')(clientCompiler, {
    publicPath: clientConfig.output.publicPath,
    noInfo: true,
    index: "/"  //指定index,解决无法直接访问根目的问题
  })
  app.use(devMiddleware)

有同种业务需要的可以参考(https://github.com/zwlijun/se.vuessr)

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