webpack/examples/web-worker/README.md

258 lines
7.4 KiB
Markdown
Raw Normal View History

2012-08-23 08:05:07 +08:00
# example.js
``` javascript
var Worker = require("worker!./worker");
var worker = new Worker;
worker.postMessage("b");
worker.onmessage = function(event) {
var templateB = event.data; // "This text was generated by template B"
}
```
# worker.js
``` javascript
onmessage = function(event) {
var template = event.data;
require(["../require.context/templates/" + event.data], function(tmpl) {
postMessage(tmpl());
});
}
```
# js/output.js
``` javascript
/******/(function(modules) {
/******/ var installedModules = {};
/******/ function require(moduleId) {
/******/ if(typeof moduleId !== "number") throw new Error("Cannot find module '"+moduleId+"'");
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ modules[moduleId](module, module.exports, require);
/******/ module.loaded = true;
/******/ return module.exports;
/******/ }
/******/ require.e = function(chunkId, callback) {
/******/ callback(require);
/******/ };
/******/ require.modules = modules;
/******/ require.cache = installedModules;
/******/ return require(0);
/******/})
/******/({c:"",
/******/0: function(module, exports, require) {
2012-11-07 19:49:01 +08:00
/**! .\example.js !**/
2012-08-23 08:05:07 +08:00
2012-11-07 19:49:01 +08:00
var Worker = require(/*! worker!./worker */1);
2012-08-23 08:05:07 +08:00
var worker = new Worker;
worker.postMessage("b");
worker.onmessage = function(event) {
var templateB = event.data; // "This text was generated by template B"
}
/******/},
/******/
/******/1: function(module, exports, require) {
2012-11-07 19:49:01 +08:00
/**! (webpack)\~\worker-loader!.\worker.js !**/
2012-08-23 08:05:07 +08:00
module.exports = function() {
return new Worker((require.modules.c||'') + "hash.worker.js");
}
2012-10-26 21:07:50 +08:00
/******/}
2012-08-23 08:05:07 +08:00
/******/})
```
# js/[hash].worker.js
``` javascript
/******/(function(modules) {
/******/ var installedModules = {}, installedChunks = {0:1};
/******/ function require(moduleId) {
/******/ if(typeof moduleId !== "number") throw new Error("Cannot find module '"+moduleId+"'");
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ modules[moduleId](module, module.exports, require);
/******/ module.loaded = true;
/******/ return module.exports;
/******/ }
/******/ require.e = function(chunkId, callback) {
/******/ if(installedChunks[chunkId] === 1) return callback(require);
/******/ importScripts(chunkId+modules.a);
/******/ callback(require);
/******/ };
/******/ require.modules = modules;
/******/ require.cache = installedModules;
/******/ this[modules.b] = function(chunkId, moreModules) {
/******/ for(var moduleId in moreModules)
/******/ modules[moduleId] = moreModules[moduleId];
/******/ installedChunks[chunkId] = 1;
/******/ };
/******/ return require(0);
/******/})
/******/({a:".hash.worker.js",b:"webpackJsonp",c:"",
/******/0: function(module, exports, require) {
2012-11-07 19:49:01 +08:00
/**! .\worker.js !**/
2012-08-23 08:05:07 +08:00
/******/ /* WEBPACK FREE VAR INJECTION */ (function(require) {
onmessage = function(event) {
var template = event.data;
2012-11-07 19:49:01 +08:00
require(1, function() { return [require(/*! ../require.context/templates */3)("./" + event.data)]}, function(tmpl) {
2012-08-23 08:05:07 +08:00
postMessage(tmpl());
});
}
2012-11-07 19:49:01 +08:00
/******/ /* WEBPACK FREE VAR INJECTION */ }(require(/*! __webpack_amd_require */1)))
2012-08-23 08:05:07 +08:00
/******/},
/******/
/******/1: function(module, exports, require) {
2012-11-07 19:49:01 +08:00
/**! (webpack)\buildin\__webpack_amd_require.js !**/
2012-08-23 08:05:07 +08:00
2012-10-09 06:12:10 +08:00
var req = require.valueOf();
function amdRequire(chunk, requiresFn, fn) {
if(!requiresFn) {
// commonjs
return req(chunk);
2012-08-23 08:05:07 +08:00
}
2012-10-09 06:12:10 +08:00
req.e(chunk, function() {
var modules = requiresFn();
if(fn)
return fn.apply(null, modules);
});
2012-08-23 08:05:07 +08:00
}
2012-10-09 06:12:10 +08:00
for(var name in req)
amdRequire[name] = req[name];
2012-11-07 19:49:01 +08:00
amdRequire.amd = require(/*! ./__webpack_options_amd.loader.js!./__webpack_options_amd.loader.js */2);
2012-10-09 06:12:10 +08:00
amdRequire.config = function() {/* config is ignored, use webpack options */};
module.exports = amdRequire;
2012-08-23 08:05:07 +08:00
/******/},
/******/
2012-10-26 21:07:50 +08:00
/******/2: function(module, exports, require) {
2012-11-07 19:49:01 +08:00
/**! (webpack)\buildin\__webpack_options_amd.loader.js!(webpack)\buildin\__webpack_options_amd.loader.js !**/
2012-10-26 21:07:50 +08:00
/* empty to return {} */
/******/}
2012-08-23 08:05:07 +08:00
/******/})
```
# Info
## Uncompressed
```
2012-11-07 19:49:01 +08:00
Hash: a017658b60f538eb1b15676e358061da
Compile Time: 70ms
2012-08-23 08:05:07 +08:00
Chunks: 1
Modules: 2
Modules including duplicates: 2
Modules first chunk: 2
2012-11-07 19:49:01 +08:00
main output.js: 1318 chars/bytes
1.hash.worker.js: 1110 chars/bytes
hash.worker.js: 2496 chars/bytes
2012-08-23 08:05:07 +08:00
<id> <size> <filename>
<reason> from <filename>
output.js
2012-11-07 19:49:01 +08:00
0 207 .\example.js
2012-08-23 08:05:07 +08:00
main
1 96 (webpack)\~\worker-loader!.\worker.js
require (1x) from .\example.js
Embedded Stats
.\worker.js
2012-11-07 19:49:01 +08:00
Hash: 5287351eed0ecaf472b73b4bca2c6807
Compile Time: 28ms
2012-08-23 08:05:07 +08:00
Chunks: 2
2012-10-26 21:07:50 +08:00
Modules: 7
Modules including duplicates: 7
Modules first chunk: 3
2012-08-23 08:05:07 +08:00
<id> <size> <filename>
<reason> from <filename>
hash.worker.js
2012-11-07 19:49:01 +08:00
0 206 .\worker.js
2012-08-23 08:05:07 +08:00
main
2012-11-07 19:49:01 +08:00
1 502 (webpack)\buildin\__webpack_amd_require.js
2012-08-23 08:05:07 +08:00
require (1x) from .\worker.js
2012-10-26 21:07:50 +08:00
2 24 (webpack)\buildin\__webpack_options_amd.loader.js!(webpack)\buildin\__webpack_options_amd.loader.js
require (1x) from (webpack)\buildin\__webpack_amd_require.js
2012-08-23 08:05:07 +08:00
1.hash.worker.js
2012-10-26 21:07:50 +08:00
3 322 [context] (webpack)\examples\require.context\templates
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
4 80 (webpack)\examples\require.context\templates\a.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
5 80 (webpack)\examples\require.context\templates\b.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
6 80 (webpack)\examples\require.context\templates\c.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
```
## Minimized (uglify-js, no zip)
```
2012-11-07 19:49:01 +08:00
Hash: b00ed9ef0ffbad2cdb698fc88413d6c7
Compile Time: 310ms
2012-08-23 08:05:07 +08:00
Chunks: 1
Modules: 2
Modules including duplicates: 2
Modules first chunk: 2
2012-11-07 19:49:01 +08:00
main output.js: 468 chars/bytes
1.hash.worker.js: 456 chars/bytes
hash.worker.js: 804 chars/bytes
2012-08-23 08:05:07 +08:00
<id> <size> <filename>
<reason> from <filename>
output.js
2012-11-07 19:49:01 +08:00
0 101 .\example.js
2012-08-23 08:05:07 +08:00
main
2012-11-07 19:49:01 +08:00
1 87 (webpack)\~\worker-loader!.\worker.js
2012-08-23 08:05:07 +08:00
require (1x) from .\example.js
Embedded Stats
.\worker.js
2012-11-07 19:49:01 +08:00
Hash: 59734387e963771414968c9e4f9bcbeb
Compile Time: 233ms
2012-08-23 08:05:07 +08:00
Chunks: 2
2012-10-26 21:07:50 +08:00
Modules: 7
Modules including duplicates: 7
Modules first chunk: 3
2012-08-23 08:05:07 +08:00
<id> <size> <filename>
<reason> from <filename>
hash.worker.js
2012-11-07 19:49:01 +08:00
0 115 .\worker.js
2012-08-23 08:05:07 +08:00
main
2012-11-07 19:49:01 +08:00
1 271 (webpack)\buildin\__webpack_amd_require.js
2012-08-23 08:05:07 +08:00
require (1x) from .\worker.js
2012-10-26 21:07:50 +08:00
2 0 (webpack)\buildin\__webpack_options_amd.loader.js!(webpack)\buildin\__webpack_options_amd.loader.js
require (1x) from (webpack)\buildin\__webpack_amd_require.js
2012-08-23 08:05:07 +08:00
1.hash.worker.js
2012-11-07 19:49:01 +08:00
3 213 [context] (webpack)\examples\require.context\templates
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
4 73 (webpack)\examples\require.context\templates\a.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
5 73 (webpack)\examples\require.context\templates\b.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
2012-11-07 19:49:01 +08:00
6 73 (webpack)\examples\require.context\templates\c.js
2012-08-23 08:05:07 +08:00
async context from .\worker.js
```