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
This leaves any dependent modules unchanged, i.e. the code shown below will still work:
42
42
43
-
```javascript
43
+
```js
44
44
import $ from'jquery';
45
45
46
46
$('.my-element').animate(...);
47
47
```
48
48
49
49
The bundle with external dependencies can be used in various module contexts, such as [CommonJS, AMD, global and ES2015 modules](/concepts/modules). The external library may be available in any of these forms:
50
50
51
-
*__root__ - An external library can be available as a global variable. The consumer can achieve this by including the external library in a script tag. This is the default setting for externals.
52
-
*__commonjs__ - The consumer application may be using a CommonJS module system and hence the external library should be available as a CommonJS module.
53
-
*__commonjs2__ - Similar to the above line but where the export is `module.exports.default`.
54
-
*__amd__ - Similar to the above line but using AMD module system.
51
+
-__root__: The library should be available as a global variable (e.g. via a script tag).
52
+
-__commonjs__: The library should be available as a CommonJS module.
53
+
-__commonjs2__: Similar to the above but where the export is `module.exports.default`.
54
+
-__amd__: Similar to `commonjs` but using AMD module system.
55
55
56
-
`externals` accepts various syntax and interprets them in different manners.
56
+
The following syntaxes are accepted and interepreted in various different ways.
57
57
58
58
59
59
### string
60
60
61
-
`jQuery` in the externals indicates that your bundle will need `jQuery` variable in the global form.
61
+
See the example above. The property name `jquery` indicates that the module `jquery` in `import $ from 'jquery'` should be excluded. In order to replace this module, the value `jQuery`will be used to retrieve a global `jQuery` variable. In other words, when a string is provided it will be treated as `root` (defined above and below).
62
62
63
63
64
64
### array
65
65
66
-
```javascript
66
+
```js
67
67
externals: {
68
68
subtract: ['./math', 'subtract']
69
69
}
@@ -74,7 +74,7 @@ externals: {
74
74
75
75
### object
76
76
77
-
```javascript
77
+
```js
78
78
externals : {
79
79
react:'react'
80
80
}
@@ -103,11 +103,11 @@ This syntax is used to describe all the possible ways that an external library c
103
103
104
104
### function
105
105
106
-
It might be useful to define your own function to control the behavior of what you want to externalize from webpack. [webpack-node-externals](https://www.npmjs.com/package/webpack-node-externals), for example, excludes all modules from the node_modules and provides some options to, for example, whitelist packages.
106
+
It might be useful to define your own function to control the behavior of what you want to externalize from webpack. [webpack-node-externals](https://www.npmjs.com/package/webpack-node-externals), for example, excludes all modules from the `node_modules` directory and provides some options to, for example, whitelist packages.
107
107
108
108
It basically comes down to this:
109
109
110
-
```javascript
110
+
```js
111
111
externals: [
112
112
function(context, request, callback) {
113
113
if (/^yourregex$/.test(request)){
@@ -125,7 +125,7 @@ The `'commonjs ' + request` defines the type of module that needs to be external
125
125
126
126
Every dependency that matches the given regular expression will be excluded from the output bundles.
0 commit comments