首页 > 关于WEBPACK DEV SERVER

关于WEBPACK DEV SERVER

关于 webpack-dev-server --content-base build/

这里的content base 是干什么用的,没看明白


比如你在src 文件夹下运行webpack-dev-server,访问http://localhost:8801/index.html 时,对应的就是src/index.html;
设置了{contentBase: 'build/'} 后,再访问http://localhost:8801/index.html,对应的就是src/build/index.html了。
类似于wwwroot。


--content-base 为资源文件夹。

The webpack-dev-server will serve the files in the current directory, unless you configure a specific content base.

webpack-dev-server默认在当前目录提供文件服务,除非你在配置中特别指定了content base选项。

output: {
  path: path.resolve(__dirname, 'build'),
  // publicPath: '/assets/',
  filename: 'bundle.js'
},

比如在webpack.config.js中写了如上的配置,如果未指定content-base,如果你想要访问到bundle.js,则需要在地址栏里写上http://localhost:5000/build/bundle.js,这个时候如果我们指定

webpack-dev-server --content-base build/

则可以直接通过http://localhost:5000/bundle.js访问到JS文件。

【热门文章】
【热门文章】