Skip to content

Commit 14875d5

Browse files
committed
add multi part library example webpack#221
1 parent 9e6b6de commit 14875d5

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
2+
# webpack.config.js
3+
4+
``` javascript
5+
var path = require("path");
6+
module.exports = {
7+
entry: {
8+
alpha: "./alpha",
9+
beta: "./beta"
10+
},
11+
output: {
12+
path: path.join(__dirname, "js"),
13+
filename: "MyLibrary.[name].js",
14+
library: ["MyLibrary", "[name]"],
15+
libraryTarget: "umd"
16+
}
17+
}
18+
```
19+
20+
# js/MyLibrary.alpha.js
21+
22+
``` javascript
23+
(function webpackUniversalModuleDefinition(root, factory) {
24+
if(typeof exports === 'object' && typeof module === 'object')
25+
module.exports = factory();
26+
else if(typeof define === 'function' && define.amd)
27+
define(factory);
28+
else if(typeof exports === 'object')
29+
exports["alpha"] = factory();
30+
else
31+
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["alpha"] = factory();
32+
})(this, function() {
33+
return /******/ (function(modules) { // webpackBootstrap
34+
/******/
35+
/******/ // The module cache
36+
/******/ var installedModules = {};
37+
/******/
38+
/******/ // The require function
39+
/******/ function __webpack_require__(moduleId) {
40+
/******/ // Check if module is in cache
41+
/******/ if(installedModules[moduleId])
42+
/******/ return installedModules[moduleId].exports;
43+
/******/
44+
/******/ // Create a new module (and put it into the cache)
45+
/******/ var module = installedModules[moduleId] = {
46+
/******/ exports: {},
47+
/******/ id: moduleId,
48+
/******/ loaded: false
49+
/******/ };
50+
/******/
51+
/******/ // Execute the module function
52+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
53+
/******/
54+
/******/ // Flag the module as loaded
55+
/******/ module.loaded = true;
56+
/******/
57+
/******/ // Return the exports of the module
58+
/******/ return module.exports;
59+
/******/ }
60+
/******/
61+
/******/
62+
/******/ // expose the modules object (__webpack_modules__)
63+
/******/ __webpack_require__.m = modules;
64+
/******/
65+
/******/ // expose the module cache
66+
/******/ __webpack_require__.c = installedModules;
67+
/******/
68+
/******/ // __webpack_public_path__
69+
/******/ __webpack_require__.p = "js/";
70+
/******/
71+
/******/
72+
/******/ // Load entry module and return exports
73+
/******/ return __webpack_require__(0);
74+
/******/ })
75+
/************************************************************************/
76+
/******/ ([
77+
/* 0 */
78+
/*!******************!*\
79+
!*** ./alpha.js ***!
80+
\******************/
81+
/***/ function(module, exports, __webpack_require__) {
82+
83+
module.exports = "alpha";
84+
85+
/***/ }
86+
/******/ ])
87+
})
88+
89+
```
90+
91+
# js/MyLibrary.beta.js
92+
93+
``` javascript
94+
(function webpackUniversalModuleDefinition(root, factory) {
95+
if(typeof exports === 'object' && typeof module === 'object')
96+
module.exports = factory();
97+
else if(typeof define === 'function' && define.amd)
98+
define(factory);
99+
else if(typeof exports === 'object')
100+
exports["beta"] = factory();
101+
else
102+
root["MyLibrary"] = root["MyLibrary"] || {}, root["MyLibrary"]["beta"] = factory();
103+
})(this, function() {
104+
return /******/ (function(modules) { // webpackBootstrap
105+
/******/
106+
/******/ // The module cache
107+
/******/ var installedModules = {};
108+
/******/
109+
/******/ // The require function
110+
/******/ function __webpack_require__(moduleId) {
111+
/******/ // Check if module is in cache
112+
/******/ if(installedModules[moduleId])
113+
/******/ return installedModules[moduleId].exports;
114+
/******/
115+
/******/ // Create a new module (and put it into the cache)
116+
/******/ var module = installedModules[moduleId] = {
117+
/******/ exports: {},
118+
/******/ id: moduleId,
119+
/******/ loaded: false
120+
/******/ };
121+
/******/
122+
/******/ // Execute the module function
123+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
124+
/******/
125+
/******/ // Flag the module as loaded
126+
/******/ module.loaded = true;
127+
/******/
128+
/******/ // Return the exports of the module
129+
/******/ return module.exports;
130+
/******/ }
131+
/******/
132+
/******/
133+
/******/ // expose the modules object (__webpack_modules__)
134+
/******/ __webpack_require__.m = modules;
135+
/******/
136+
/******/ // expose the module cache
137+
/******/ __webpack_require__.c = installedModules;
138+
/******/
139+
/******/ // __webpack_public_path__
140+
/******/ __webpack_require__.p = "js/";
141+
/******/
142+
/******/
143+
/******/ // Load entry module and return exports
144+
/******/ return __webpack_require__(0);
145+
/******/ })
146+
/************************************************************************/
147+
/******/ ([
148+
/* 0 */
149+
/*!*****************!*\
150+
!*** ./beta.js ***!
151+
\*****************/
152+
/***/ function(module, exports, __webpack_require__) {
153+
154+
module.exports = "beta";
155+
156+
/***/ }
157+
/******/ ])
158+
})
159+
160+
```
161+
162+
# Info
163+
164+
## Uncompressed
165+
166+
```
167+
Hash: 188fa9bfc8c26494bc09
168+
Version: webpack 1.1.3
169+
Time: 126ms
170+
Asset Size Chunks Chunk Names
171+
MyLibrary.beta.js 2047 0 [emitted] beta
172+
MyLibrary.alpha.js 2053 1 [emitted] alpha
173+
chunk {0} MyLibrary.beta.js (beta) 24 [rendered]
174+
> beta [0] ./beta.js
175+
[0] ./beta.js 24 {0} [built]
176+
chunk {1} MyLibrary.alpha.js (alpha) 25 [rendered]
177+
> alpha [0] ./alpha.js
178+
[0] ./alpha.js 25 {1} [built]
179+
```
180+
181+
## Minimized (uglify-js, no zip)
182+
183+
```
184+
Hash: 7ddebca59251e5368cb3
185+
Version: webpack 1.1.3
186+
Time: 380ms
187+
Asset Size Chunks Chunk Names
188+
MyLibrary.beta.js 485 0 [emitted] beta
189+
MyLibrary.alpha.js 488 1 [emitted] alpha
190+
chunk {0} MyLibrary.beta.js (beta) 24 [rendered]
191+
> beta [0] ./beta.js
192+
[0] ./beta.js 24 {0} [built]
193+
chunk {1} MyLibrary.alpha.js (alpha) 25 [rendered]
194+
> alpha [0] ./alpha.js
195+
[0] ./alpha.js 25 {1} [built]
196+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "alpha";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "beta";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.NO_TARGET_ARGS = true;
2+
require("../build-common");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
# webpack.config.js
3+
4+
``` javascript
5+
{{webpack.config.js}}
6+
```
7+
8+
# js/MyLibrary.alpha.js
9+
10+
``` javascript
11+
{{js/MyLibrary.alpha.js}}
12+
```
13+
14+
# js/MyLibrary.beta.js
15+
16+
``` javascript
17+
{{js/MyLibrary.beta.js}}
18+
```
19+
20+
# Info
21+
22+
## Uncompressed
23+
24+
```
25+
{{stdout}}
26+
```
27+
28+
## Minimized (uglify-js, no zip)
29+
30+
```
31+
{{min:stdout}}
32+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var path = require("path");
2+
module.exports = {
3+
entry: {
4+
alpha: "./alpha",
5+
beta: "./beta"
6+
},
7+
output: {
8+
path: path.join(__dirname, "js"),
9+
filename: "MyLibrary.[name].js",
10+
library: ["MyLibrary", "[name]"],
11+
libraryTarget: "umd"
12+
}
13+
}

0 commit comments

Comments
 (0)