You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Specify a host to use. If you want your server to be accessible externally, specify it like this:
669
669
@@ -1083,16 +1083,208 @@ module.exports = {
1083
1083
1084
1084
`boolean``string``[string]``object``[object]`
1085
1085
1086
+
This options allows to configure options for serving static files from directory (by default 'public' directory). To disable set it to `false`:
1087
+
1088
+
**webpack.config.js**
1089
+
1090
+
```javascript
1091
+
module.exports= {
1092
+
//...
1093
+
devServer: {
1094
+
static:false,
1095
+
},
1096
+
};
1097
+
```
1098
+
1099
+
Usage via CLI:
1100
+
1101
+
```bash
1102
+
npx webpack serve --static
1103
+
```
1104
+
1105
+
To disable:
1106
+
1107
+
```bash
1108
+
npx webpack serve --no-static
1109
+
```
1110
+
1086
1111
### directory
1087
1112
1113
+
`string = path.join(process.cwd(), 'public')`
1114
+
1115
+
Tell the server where to serve the content from. This is only necessary if you want to serve static files. [static.publicPath](#publicpath) will be used to determine where the bundles should be served from, and takes precedence.
1116
+
1117
+
**webpack.config.js**
1118
+
1119
+
```javascript
1120
+
constpath=require('path');
1121
+
1122
+
module.exports= {
1123
+
//...
1124
+
devServer: {
1125
+
static: {
1126
+
directory:path.join(__dirname, 'public'),
1127
+
},
1128
+
},
1129
+
};
1130
+
```
1131
+
1132
+
T> It is recommended to use an absolute path.
1133
+
1088
1134
### staticOptions
1089
1135
1136
+
It is possible to configure advanced options for serving static files from [static.directory](#directory). See the [Express documentation](http://expressjs.com/en/4x/api.html#express.static) for the possible options.
1137
+
1138
+
**webpack.config.js**
1139
+
1140
+
```javascript
1141
+
module.exports= {
1142
+
//...
1143
+
devServer: {
1144
+
static: {
1145
+
staticOptions: {
1146
+
redirect:true,
1147
+
},
1148
+
},
1149
+
},
1150
+
};
1151
+
```
1152
+
1090
1153
### publicPath
1091
1154
1155
+
`string = '/'``string`
1156
+
1157
+
Tell the server at which URL to serve [`static.directory`](#directory) content. For example to serve a file `assets/manifest.json` at `/serve-public-path-url/manifest.json`, your configurations should be as following:
1158
+
1159
+
**webpack.config.js**
1160
+
1161
+
```javascript
1162
+
constpath=require('path');
1163
+
1164
+
module.exports= {
1165
+
//...
1166
+
devServer: {
1167
+
static: {
1168
+
directory:path.join(__dirname, 'assets'),
1169
+
publicPath:'/serve-public-path-url',
1170
+
},
1171
+
},
1172
+
};
1173
+
```
1174
+
1175
+
Provide an array of objects in case you have multiple static folders:
1176
+
1177
+
**webpack.config.js**
1178
+
1179
+
```javascript
1180
+
constpath=require('path');
1181
+
1182
+
module.exports= {
1183
+
//...
1184
+
devServer: {
1185
+
static: [
1186
+
{
1187
+
directory:path.join(__dirname, 'assets'),
1188
+
publicPath:'/serve-public-path-url',
1189
+
},
1190
+
{
1191
+
directory:path.join(__dirname, 'css'),
1192
+
publicPath:'/other-serve-public-path-url',
1193
+
},
1194
+
],
1195
+
},
1196
+
};
1197
+
```
1198
+
1092
1199
### serveIndex
1093
1200
1201
+
`boolean``object = { icons: true }`
1202
+
1203
+
Tell dev-server to use [`serveIndex`](https://github.com/expressjs/serve-index) middleware when enabled.
1204
+
1205
+
[`serveIndex`](https://github.com/expressjs/serve-index) middleware generates directory listings on viewing directories that don't have an `index.html` file.
1206
+
1207
+
**webpack.config.js**
1208
+
1209
+
```javascript
1210
+
constpath=require('path');
1211
+
1212
+
module.exports= {
1213
+
//...
1214
+
devServer: {
1215
+
static: {
1216
+
directory:path.join(__dirname, 'public'),
1217
+
serveIndex:true,
1218
+
},
1219
+
},
1220
+
};
1221
+
```
1222
+
1223
+
Usage via CLI:
1224
+
1225
+
```bash
1226
+
npx webpack serve --static-serve-index
1227
+
```
1228
+
1229
+
To disable:
1230
+
1231
+
```bash
1232
+
npx webpack serve --no-static-serve-index
1233
+
```
1234
+
1094
1235
### watch
1095
1236
1237
+
`boolean``object`
1238
+
1239
+
Tell dev-server to watch the files served by the [static.directory]($directory) option. It is disabled by default. When enabled, file changes will trigger a full page reload.
1240
+
1241
+
**webpack.config.js**
1242
+
1243
+
```javascript
1244
+
constpath=require('path');
1245
+
1246
+
module.exports= {
1247
+
//...
1248
+
devServer: {
1249
+
static: {
1250
+
directory:path.join(__dirname, 'public'),
1251
+
watch:true,
1252
+
},
1253
+
},
1254
+
};
1255
+
```
1256
+
1257
+
Usage via CLI:
1258
+
1259
+
```bash
1260
+
npx webpack serve --static-watch
1261
+
```
1262
+
1263
+
To disable:
1264
+
1265
+
```bash
1266
+
npx webpack serve --no-static-watch
1267
+
```
1268
+
1269
+
It is possible to configure advanced options for watching static files from [static.directory](#directory). See the [chokidar](https://github.com/paulmillr/chokidar) documentation for the possible options.
0 commit comments