Skip to content

Commit 3f2b148

Browse files
authored
docs(configuration): document buildHttp (#5276)
* docs(configuration): sort options * add buildHttp * docs(configuration): document buildHttp * optimize * docs(configuration): optimize
1 parent f5902ee commit 3f2b148

File tree

1 file changed

+89
-4
lines changed

1 file changed

+89
-4
lines changed

src/content/configuration/experiments.mdx

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ contributors:
88
- anshumanv
99
---
1010

11-
## `experiments`
11+
## experiments
1212

1313
`boolean: false`
1414

@@ -19,6 +19,7 @@ W> Because experimental features have relaxed semantic versioning and might cont
1919
Available options:
2020

2121
- `asyncWebAssembly`: Support the new WebAssembly according to the [updated specification](https://github.com/WebAssembly/esm-integration), it makes a WebAssembly module an async module.
22+
- [`buildHttp`](#experimentsbuildhttp)
2223
- [`executeModule`](#experimentsexecutemodule)
2324
- `layers`: Enable module and chunk layers.
2425
- [`lazyCompilation`](#experimentslazycompilation)
@@ -32,17 +33,101 @@ Available options:
3233
module.exports = {
3334
//...
3435
experiments: {
36+
asyncWebAssembly: true,
37+
buildHttp: true,
3538
executeModule: true,
39+
layers: true,
40+
lazyCompilation: true,
3641
outputModule: true,
3742
syncWebAssembly: true,
3843
topLevelAwait: true,
39-
asyncWebAssembly: true,
40-
layers: true,
41-
lazyCompilation: true,
4244
},
4345
};
4446
```
4547

48+
### experiments.buildHttp
49+
50+
When enabled, webpack can build remote resources that begin with the `http(s):` protocol.
51+
52+
- Type:
53+
54+
One of the following:
55+
56+
- `boolean`
57+
- `HttpUriOptions`
58+
```ts
59+
{
60+
cacheLocation?: false | string,
61+
frozen?: boolean,
62+
lockfileLocation?: string,
63+
upgrade?: boolean
64+
}
65+
```
66+
67+
- Available: 5.49.0+
68+
- Example
69+
70+
```javascript
71+
// webpack.config.js
72+
module.exports = {
73+
//...
74+
experiments: {
75+
buildHttp: true,
76+
},
77+
};
78+
```
79+
80+
```js
81+
// src/index.js
82+
import pMap1 from 'https://cdn.skypack.dev/p-map';
83+
// with `buildHttp` enabled, webpack will build pMap1 just like a regular local module
84+
console.log(pMap1);
85+
```
86+
87+
#### experiments.buildHttp.cacheLocation
88+
89+
Define the location for caching remote resources.
90+
91+
- Type
92+
- `string`
93+
- `false`
94+
- Example
95+
```javascript
96+
// webpack.config.js
97+
module.exports = {
98+
//...
99+
experiments: {
100+
buildHttp: {
101+
cacheLocation: false,
102+
},
103+
},
104+
};
105+
```
106+
107+
By default webpack would use `<compiler-name.>webpack.lock.data/` for caching, but you can disable it by setting its value to `false`.
108+
109+
Note that you should commit files under `experiments.buildHttp.cacheLocation` into a version control system as no network requests will be made during the `production` build.
110+
111+
#### experiments.buildHttp.frozen
112+
113+
Freeze the remote resources and lockfile. Any modification to the lockfile or resource contents will result in an error.
114+
115+
- Type: `boolean`
116+
117+
#### experiments.buildHttp.lockfileLocation
118+
119+
Define the location to store the lockfile.
120+
121+
- Type: `string`
122+
123+
By default webpack would generate a `<compiler-name.>webpack.lock` file>. Make sure to commit it into a version control system. During the `production` build, webpack will build those modules beginning with `http(s):` protocol from the lockfile and caches under [`experiments.buildHttp.cacheLocation`](#experimentsbuildhttpcachelocation).
124+
125+
#### experiments.buildHttp.upgrade
126+
127+
Detect changes to remote resources and upgrade them automatically.
128+
129+
- Type: `boolean`
130+
46131
### experiments.executeModule
47132

48133
Enable execution of modules from the module graph for plugins and loaders at build time to generate code or other assets.

0 commit comments

Comments
 (0)