Skip to content

Commit 4fdf62b

Browse files
committed
added DllReferencePlugin
1 parent 817e678 commit 4fdf62b

9 files changed

Lines changed: 214 additions & 81 deletions

File tree

‎examples/dll-user/README.md‎

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# example.js
2+
3+
``` javascript
4+
console.log(require("../dll/alpha"));
5+
console.log(require("../dll/a"));
6+
7+
//console.log(require("beta/beta"));
8+
//console.log(require("beta/b"));
9+
```
10+
11+
# js/output.js
12+
13+
``` javascript
14+
/******/ (function(modules) { // webpackBootstrap
15+
/******/ // The module cache
16+
/******/ var installedModules = {};
17+
18+
/******/ // The require function
19+
/******/ function __webpack_require__(moduleId) {
20+
21+
/******/ // Check if module is in cache
22+
/******/ if(installedModules[moduleId])
23+
/******/ return installedModules[moduleId].exports;
24+
25+
/******/ // Create a new module (and put it into the cache)
26+
/******/ var module = installedModules[moduleId] = {
27+
/******/ exports: {},
28+
/******/ id: moduleId,
29+
/******/ loaded: false
30+
/******/ };
31+
32+
/******/ // Execute the module function
33+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
34+
35+
/******/ // Flag the module as loaded
36+
/******/ module.loaded = true;
37+
38+
/******/ // Return the exports of the module
39+
/******/ return module.exports;
40+
/******/ }
41+
42+
43+
/******/ // expose the modules object (__webpack_modules__)
44+
/******/ __webpack_require__.m = modules;
45+
46+
/******/ // expose the module cache
47+
/******/ __webpack_require__.c = installedModules;
48+
49+
/******/ // __webpack_public_path__
50+
/******/ __webpack_require__.p = "js/";
51+
52+
/******/ // Load entry module and return exports
53+
/******/ return __webpack_require__(0);
54+
/******/ })
55+
/************************************************************************/
56+
/******/ ([
57+
/* 0 */
58+
/*!********************!*\
59+
!*** ./example.js ***!
60+
\********************/
61+
/***/ function(module, exports, __webpack_require__) {
62+
63+
console.log(__webpack_require__(/*! ../dll/alpha */ 1));
64+
console.log(__webpack_require__(/*! ../dll/a */ 3));
65+
66+
//console.log(require("beta/beta"));
67+
//console.log(require("beta/b"));
68+
69+
70+
/***/ },
71+
/* 1 */
72+
/*!*****************************************************************!*\
73+
!*** delegated 1 from dll-reference alpha_fda802f3c408a66ef744 ***!
74+
\*****************************************************************/
75+
/***/ function(module, exports, __webpack_require__) {
76+
77+
module.exports = (__webpack_require__(2))(1);
78+
79+
/***/ },
80+
/* 2 */
81+
/*!*********************************************!*\
82+
!*** external "alpha_fda802f3c408a66ef744" ***!
83+
\*********************************************/
84+
/***/ function(module, exports, __webpack_require__) {
85+
86+
module.exports = alpha_fda802f3c408a66ef744;
87+
88+
/***/ },
89+
/* 3 */
90+
/*!*****************************************************************!*\
91+
!*** delegated 2 from dll-reference alpha_fda802f3c408a66ef744 ***!
92+
\*****************************************************************/
93+
/***/ function(module, exports, __webpack_require__) {
94+
95+
module.exports = (__webpack_require__(2))(2);
96+
97+
/***/ }
98+
/******/ ]);
99+
```
100+
101+
# Info
102+
103+
## Uncompressed
104+
105+
```
106+
Hash: 08ef761d3df9cb02c0ab
107+
Version: webpack 1.9.5
108+
Time: 43ms
109+
Asset Size Chunks Chunk Names
110+
output.js 2.62 kB 0 [emitted] main
111+
chunk {0} output.js (main) 275 bytes [rendered]
112+
> main [0] ./example.js
113+
[0] ./example.js 149 bytes {0} [built]
114+
+ 3 hidden modules
115+
```
116+
117+
## Minimized (uglify-js, no zip)
118+
119+
```
120+
Hash: c02a95197e755bb65192
121+
Version: webpack 1.9.5
122+
Time: 107ms
123+
Asset Size Chunks Chunk Names
124+
output.js 382 bytes 0 [emitted] main
125+
chunk {0} output.js (main) 275 bytes [rendered]
126+
> main [0] ./example.js
127+
[0] ./example.js 149 bytes {0} [built]
128+
+ 3 hidden modules
129+
```

‎examples/dll-user/build.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("../build-common");

‎examples/dll-user/example.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log(require("../dll/alpha"));
2+
console.log(require("../dll/a"));
3+
4+
//console.log(require("beta/beta"));
5+
//console.log(require("beta/b"));

‎examples/dll-user/template.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# example.js
2+
3+
``` javascript
4+
{{example.js}}
5+
```
6+
7+
# js/output.js
8+
9+
``` javascript
10+
{{js/output.js}}
11+
```
12+
13+
# Info
14+
15+
## Uncompressed
16+
17+
```
18+
{{stdout}}
19+
```
20+
21+
## Minimized (uglify-js, no zip)
22+
23+
```
24+
{{min:stdout}}
25+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var path = require("path");
2+
var DllReferencePlugin = require("../../lib/DllReferencePlugin");
3+
module.exports = {
4+
plugins: [
5+
new DllReferencePlugin({
6+
context: path.join(__dirname, "..", "dll"),
7+
manifest: require("../dll/js/alpha-manifest.json")
8+
}),
9+
/* new DllReferencePlugin({
10+
scope: "beta",
11+
manifest: require("../dll/js/beta-manifest.json")
12+
})
13+
*/ ]
14+
};

‎examples/dll/README.md‎

Lines changed: 10 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -99,83 +99,16 @@ var alpha_fda802f3c408a66ef744 =
9999
/******/ ]);
100100
```
101101

102-
# js/MyDll.beta.js
102+
# js/alpha-manifest.json
103103

104104
``` javascript
105-
var beta_fda802f3c408a66ef744 =
106-
/******/ (function(modules) { // webpackBootstrap
107-
/******/ // The module cache
108-
/******/ var installedModules = {};
109-
110-
/******/ // The require function
111-
/******/ function __webpack_require__(moduleId) {
112-
113-
/******/ // Check if module is in cache
114-
/******/ if(installedModules[moduleId])
115-
/******/ return installedModules[moduleId].exports;
116-
117-
/******/ // Create a new module (and put it into the cache)
118-
/******/ var module = installedModules[moduleId] = {
119-
/******/ exports: {},
120-
/******/ id: moduleId,
121-
/******/ loaded: false
122-
/******/ };
123-
124-
/******/ // Execute the module function
125-
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
126-
127-
/******/ // Flag the module as loaded
128-
/******/ module.loaded = true;
129-
130-
/******/ // Return the exports of the module
131-
/******/ return module.exports;
132-
/******/ }
133-
134-
135-
/******/ // expose the modules object (__webpack_modules__)
136-
/******/ __webpack_require__.m = modules;
137-
138-
/******/ // expose the module cache
139-
/******/ __webpack_require__.c = installedModules;
140-
141-
/******/ // __webpack_public_path__
142-
/******/ __webpack_require__.p = "js/";
143-
144-
/******/ // Load entry module and return exports
145-
/******/ return __webpack_require__(0);
146-
/******/ })
147-
/************************************************************************/
148-
/******/ ([
149-
/* 0 */
150-
/*!****************!*\
151-
!*** dll beta ***!
152-
\****************/
153-
/***/ function(module, exports, __webpack_require__) {
154-
155-
module.exports = __webpack_require__;
156-
157-
/***/ },
158-
/* 1 */,
159-
/* 2 */,
160-
/* 3 */
161-
/*!*****************!*\
162-
!*** ./beta.js ***!
163-
\*****************/
164-
/***/ function(module, exports, __webpack_require__) {
165-
166-
module.exports = "beta";
167-
168-
/***/ },
169-
/* 4 */
170-
/*!**************!*\
171-
!*** ./b.js ***!
172-
\**************/
173-
/***/ function(module, exports, __webpack_require__) {
174-
175-
module.exports = "b";
176-
177-
/***/ }
178-
/******/ ]);
105+
{
106+
"name": "alpha_fda802f3c408a66ef744",
107+
"content": {
108+
"./alpha.js": 1,
109+
"./a.js": 2
110+
}
111+
}
179112
```
180113

181114
# Info
@@ -185,7 +118,7 @@ var beta_fda802f3c408a66ef744 =
185118
```
186119
Hash: fda802f3c408a66ef744
187120
Version: webpack 1.9.5
188-
Time: 54ms
121+
Time: 47ms
189122
Asset Size Chunks Chunk Names
190123
MyDll.alpha.js 1.88 kB 0 [emitted] alpha
191124
MyDll.beta.js 1.89 kB 1 [emitted] beta
@@ -210,7 +143,7 @@ chunk {1} MyDll.beta.js (beta) 57 bytes [rendered]
210143
```
211144
Hash: 28b01778c3ed267edad7
212145
Version: webpack 1.9.5
213-
Time: 129ms
146+
Time: 130ms
214147
Asset Size Chunks Chunk Names
215148
MyDll.beta.js 330 bytes 0 [emitted] beta
216149
MyDll.alpha.js 330 bytes 1 [emitted] alpha

‎examples/dll/template.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
{{js/MyDll.alpha.js}}
1111
```
1212

13-
# js/MyDll.beta.js
13+
# js/alpha-manifest.json
1414

1515
``` javascript
16-
{{js/MyDll.beta.js}}
16+
{{js/alpha-manifest.json}}
1717
```
1818

1919
# Info

‎lib/DllReferencePlugin.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
5+
var DelegatedPlugin = require("./DelegatedPlugin");
6+
var ExternalsPlugin = require("./ExternalsPlugin");
7+
8+
function DllReferencePlugin(options) {
9+
this.options = options;
10+
}
11+
module.exports = DllReferencePlugin;
12+
DllReferencePlugin.prototype.apply = function(compiler) {
13+
var name = this.options.name || this.options.manifest.name;
14+
var sourceType = this.options.sourceType || "var";
15+
var externals = {};
16+
var source = "dll-reference " + name;
17+
externals[source] = name;
18+
compiler.apply(new ExternalsPlugin(sourceType, externals));
19+
compiler.apply(new DelegatedPlugin({
20+
source: source,
21+
type: this.options.type,
22+
scope: this.options.scope,
23+
context: this.options.context,
24+
content: this.options.content || this.options.manifest.content
25+
}));
26+
};

‎lib/LibManifestPlugin.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ LibManifestPlugin.prototype.apply = function(compiler) {
2525
var manifest = {
2626
name: name,
2727
type: this.options.type,
28-
modules: chunk.modules.reduce(function(obj, module) {
28+
content: chunk.modules.reduce(function(obj, module) {
2929
if(module.libIdent) {
3030
var ident = module.libIdent({
3131
context: this.options.context || compiler.options.context
@@ -37,7 +37,7 @@ LibManifestPlugin.prototype.apply = function(compiler) {
3737
return obj;
3838
}.bind(this), {})
3939
};
40-
var content = new Buffer(JSON.stringify(manifest), "utf-8");
40+
var content = new Buffer(JSON.stringify(manifest, null, 2), "utf-8");
4141
compiler.outputFileSystem.mkdirp(path.dirname(targetPath), function(err) {
4242
if(err) return callback(err);
4343
compiler.outputFileSystem.writeFile(targetPath, content, callback);

0 commit comments

Comments
 (0)