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
// Adds the `map` and `reduce` method from `underscore` to the `global` object under the name `_.map` and `_.reduce`
57
+
// Adds the `map` and `reduce` method from `underscore` to the global object under the name `_.map` and `_.reduce`
58
58
```
59
59
60
+
The `|` or `%20` (space) allow to separate the export name of the module and the name in the global object.
61
+
62
+
> ⚠ `%20` is space in a query string, because you can't use spaces in URLs
63
+
60
64
Description of string values can be found in the documentation below.
61
65
62
66
## Using Configuration
@@ -125,12 +129,13 @@ List of exposes.
125
129
126
130
Allows to use a string to describe an expose.
127
131
128
-
String syntax - `[[globalName] [moduleLocalName]]` or `[[globalName]|[moduleLocalName]]`, where:
132
+
String syntax - `[[globalName] [moduleLocalName] [override]]` or `[[globalName]|[moduleLocalName]|[override]]`, where:
129
133
130
-
-`globalName` - the name under which the value will be available in the global scope, for example `windows.$` for a browser environment (**required**)
131
-
-`moduleLocalName` - the name of method or variable (module should export it) (**may be omitted**)
134
+
-`globalName` - the name in the global object, for example `window.$` for a browser environment (**required**)
135
+
-`moduleLocalName` - the name of method/variable/etc of the module (the module must export it) (**may be omitted**)
136
+
-`override` - allows to override existing value in the global object (**may be omitted**)
132
137
133
-
If no `moduleLocalName` is specified, it exposes the entire module to global scope, otherwise it exposes only the `moduleLocalName` value.
138
+
If `moduleLocalName` is not specified, it exposes the entire module to the global object, otherwise it exposes only the value of `moduleLocalName`.
134
139
135
140
**src/index.js**
136
141
@@ -166,7 +171,7 @@ Allows to use an object to describe an expose.
166
171
Type: `String|Array<String>`
167
172
Default: `undefined`
168
173
169
-
Name of an exposed value in `global` scope (**required**).
174
+
The name in the global object. (**required**).
170
175
171
176
**src/index.js**
172
177
@@ -201,9 +206,8 @@ module.exports = {
201
206
Type: `String`
202
207
Default: `undefined`
203
208
204
-
Name of method or variable (module should export it).
205
-
206
-
If the `moduleLocalName` option is specified, it exposes only the `moduleLocalName` value.
209
+
The name of method/variable/etc of the module (the module must export it).
210
+
If `moduleLocalName` is specified, it exposes only the value of `moduleLocalName`.
207
211
208
212
**src/index.js**
209
213
@@ -232,6 +236,44 @@ module.exports = {
232
236
};
233
237
```
234
238
239
+
##### `override`
240
+
241
+
Type: `Boolean`
242
+
Default: `false`
243
+
244
+
By default loader does not override the existing value in the global object, because it is unsafe.
245
+
In `development` mode, we throw an error if the value already present in the global object.
246
+
But you can configure loader to override the existing value in the global object using this option.
247
+
248
+
To force override the value that is already present in the global object you can set the `override` option to the `true` value.
249
+
250
+
**src/index.js**
251
+
252
+
```js
253
+
import $ from'jquery';
254
+
```
255
+
256
+
**webpack.config.js**
257
+
258
+
```js
259
+
module.exports= {
260
+
module: {
261
+
rules: [
262
+
{
263
+
test:require.resolve('jquery'),
264
+
loader:'expose-loader',
265
+
options: {
266
+
exposes: {
267
+
globalName:'$',
268
+
override:true,
269
+
},
270
+
},
271
+
},
272
+
],
273
+
},
274
+
};
275
+
```
276
+
235
277
#### `Array`
236
278
237
279
**src/index.js**
@@ -268,7 +310,7 @@ module.exports = {
268
310
};
269
311
```
270
312
271
-
It will expose **only**`map`, `filter` and `find` (under `myNameForFind` name) methods in global scope.
313
+
It will expose **only**`map`, `filter` and `find` (under `myNameForFind` name) methods to the global object.
272
314
273
315
In a browser these methods will be available under `windows._.map(..args)`, `windows._.filter(...args)` and `windows._.myNameForFind(...args)` methods.
0 commit comments