Skip to content

Commit 7ac4dbd

Browse files
committed
externals example
1 parent 973d81d commit 7ac4dbd

3 files changed

Lines changed: 67 additions & 27 deletions

File tree

examples/externals/README.md

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,46 @@
33

44
``` javascript
55
var add = require("add");
6+
var subtract = require("subtract");
67

7-
module.exports = add(40, 2);
8+
exports.exampleValue = subtract(add(42, 2), 2);
89
```
910

1011
# webpack.config.js
1112

1213
``` javascript
1314
module.exports = {
1415
output: {
15-
libraryTarget: "this"
16+
libraryTarget: "umd"
1617
},
17-
externals: {
18-
"add": true
19-
}
18+
externals: [
19+
"add",
20+
{
21+
"subtract": {
22+
root: "subtract",
23+
commonjs2: "./subtract",
24+
commonjs: ["./math", "subtract"],
25+
amd: "subtract"
26+
}
27+
}
28+
]
2029
}
2130
```
2231

2332
# js/output.js
2433

2534
``` javascript
26-
(function(e, a) { for(var i in a) e[i] = a[i]; }(this, /******/ (function(modules) { // webpackBootstrap
35+
(function webpackUniversalModuleDefinition(root, factory) {
36+
if(typeof exports === 'object' && typeof module === 'object')
37+
module.exports = factory(require("add"), require("./subtract"));
38+
else if(typeof define === 'function' && define.amd)
39+
define(["add", "subtract"], factory);
40+
else {
41+
var a = typeof exports === 'object' ? factory(require("add"), require("./math")["subtract"]) : factory(root["add"], root["subtract"]);
42+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
43+
}
44+
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_2__) {
45+
return /******/ (function(modules) { // webpackBootstrap
2746
/******/
2847
/******/ // The module cache
2948
/******/ var installedModules = {};
@@ -74,46 +93,58 @@ module.exports = {
7493
/***/ function(module, exports, __webpack_require__) {
7594

7695
var add = __webpack_require__(/*! add */ 1);
96+
var subtract = __webpack_require__(/*! subtract */ 2);
7797

78-
module.exports = add(40, 2);
98+
exports.exampleValue = subtract(add(42, 2), 2);
7999

80100
/***/ },
81101
/* 1 */
82-
/*!********************!*\
83-
!*** external add ***!
84-
\********************/
102+
/*!**********************!*\
103+
!*** external "add" ***!
104+
\**********************/
85105
/***/ function(module, exports, __webpack_require__) {
86106

87-
(function() { module.exports = this["add"]; }());
107+
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
108+
109+
/***/ },
110+
/* 2 */
111+
/*!***************************************************************************************************************!*\
112+
!*** external {"root":"subtract","commonjs2":"./subtract","commonjs":["./math","subtract"],"amd":"subtract"} ***!
113+
\***************************************************************************************************************/
114+
/***/ function(module, exports, __webpack_require__) {
115+
116+
module.exports = __WEBPACK_EXTERNAL_MODULE_2__;
88117

89118
/***/ }
90-
/******/ ])))
119+
/******/ ])
120+
})
121+
91122
```
92123

93124
# Info
94125

95126
## Uncompressed
96127

97128
```
98-
Hash: 4b1215a5724ebdb340c6
129+
Hash: fe82a5dbd0c1deac91fe
99130
Version: webpack 1.1.0-beta1
100-
Time: 213ms
131+
Time: 127ms
101132
Asset Size Chunks Chunk Names
102-
output.js 1949 0 [emitted] main
103-
chunk {0} output.js (main) 99 [rendered]
133+
output.js 3045 0 [emitted] main
134+
chunk {0} output.js (main) 197 [rendered]
104135
> main [0] ./example.js
105-
[0] ./example.js 57 {0} [built]
136+
[0] ./example.js 113 {0} [built]
106137
```
107138

108139
## Minimized (uglify-js, no zip)
109140

110141
```
111-
Hash: 9397fce116b2fe76bdb7
142+
Hash: 477ae8800e910830898c
112143
Version: webpack 1.1.0-beta1
113-
Time: 293ms
144+
Time: 364ms
114145
Asset Size Chunks Chunk Names
115-
output.js 344 0 [emitted] main
116-
chunk {0} output.js (main) 99 [rendered]
146+
output.js 706 0 [emitted] main
147+
chunk {0} output.js (main) 197 [rendered]
117148
> main [0] ./example.js
118-
[0] ./example.js 57 {0} [built]
149+
[0] ./example.js 113 {0} [built]
119150
```

examples/externals/example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
var add = require("add");
2+
var subtract = require("subtract");
23

3-
module.exports = add(40, 2);
4+
exports.exampleValue = subtract(add(42, 2), 2);
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
module.exports = {
22
output: {
3-
libraryTarget: "this"
3+
libraryTarget: "umd"
44
},
5-
externals: {
6-
"add": true
7-
}
5+
externals: [
6+
"add",
7+
{
8+
"subtract": {
9+
root: "subtract",
10+
commonjs2: "./subtract",
11+
commonjs: ["./math", "subtract"],
12+
amd: "subtract"
13+
}
14+
}
15+
]
816
}

0 commit comments

Comments
 (0)