webpack 的 devServer 的默认根目录是什么?
What is the default root directory for webpack's devServer?
我已经配置了 Webpack,具有以下 devServer 配置:
devServer:{
port: 8080,
host: 'localhost',
publicPath: 'http://localhost:8080/',
...
}
我怎么知道开发服务器的根目录在哪里。
在 webpack 的 documentation 中,有一个设置 devServer.contentBase
,我的配置中没有这个设置。
devServer.contentBase
(boolean string array)
Tell the server where to serve content from. This is only necessary if you want to serve static files. devServer.publicPath will be used to determine where the bundles should be served from, and takes precedence.
By default it will use your current working directory to serve content, but you can modify this to another directory:
我只是不明白 devServer.publicPath
如何告诉服务器从哪里提供内容!
[更新]
我认为它提供来自 Webpack 中 output.path
设置的文件。但不确定。
检查下面的代码,如果您看到 publicPath: '/'
表示它将获取 webpack.config.js
所在的目录。
devServer: {
open: 'http://localhost:9000',
port: 9000,
publicPath: "/",
},
如果要指定文件夹,需要像下面这样传递文件夹名称。
devServer: {
open: 'http://localhost:9000',
port: 9000,
publicPath: "/foldername",
},
我已经配置了 Webpack,具有以下 devServer 配置:
devServer:{
port: 8080,
host: 'localhost',
publicPath: 'http://localhost:8080/',
...
}
我怎么知道开发服务器的根目录在哪里。
在 webpack 的 documentation 中,有一个设置 devServer.contentBase
,我的配置中没有这个设置。
devServer.contentBase (boolean string array)
Tell the server where to serve content from. This is only necessary if you want to serve static files. devServer.publicPath will be used to determine where the bundles should be served from, and takes precedence.
By default it will use your current working directory to serve content, but you can modify this to another directory:
我只是不明白 devServer.publicPath
如何告诉服务器从哪里提供内容!
[更新]
我认为它提供来自 Webpack 中 output.path
设置的文件。但不确定。
检查下面的代码,如果您看到 publicPath: '/'
表示它将获取 webpack.config.js
所在的目录。
devServer: {
open: 'http://localhost:9000',
port: 9000,
publicPath: "/",
},
如果要指定文件夹,需要像下面这样传递文件夹名称。
devServer: {
open: 'http://localhost:9000',
port: 9000,
publicPath: "/foldername",
},