webpack/examples/web-worker/README.md

179 lines
5.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
2013-01-31 01:49:25 +08:00
/******/ (function webpackBootstrap(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].call(null, module, module.exports, require);
/******/ module.loaded = true;
/******/ return module.exports;
/******/ }
/******/ require.e = function requireEnsure(chunkId, callback) {
/******/ callback.call(null, require);
/******/ };
/******/ require.modules = modules;
/******/ require.cache = installedModules;
/******/ return require(0);
/******/ })({
/******/ c: "",
/***/ 0:
/*!********************!*\
!*** ./example.js ***!
\********************/
/***/ function(module, exports, require) {
var Worker = require(/*! worker!./worker */ 1);
var worker = new Worker;
worker.postMessage("b");
worker.onmessage = function(event) {
var templateB = event.data; // "This text was generated by template B"
}
2012-08-23 08:05:07 +08:00
2013-01-31 01:49:25 +08:00
/***/ },
2012-08-23 08:05:07 +08:00
2013-01-31 01:49:25 +08:00
/***/ 1:
2013-01-31 10:25:20 +08:00
/*!**************************************************************************************!*\
!*** C:/Users/Sokrates/Eigene Repos/webpack-development/~/worker-loader!./worker.js ***!
\**************************************************************************************/
2013-01-31 01:49:25 +08:00
/***/ function(module, exports, require) {
2012-08-23 08:05:07 +08:00
2013-01-31 01:49:25 +08:00
module.exports = function() {
2013-01-31 10:25:20 +08:00
return new Worker(require.modules.c + "hash.worker.js");
2013-01-31 01:49:25 +08:00
};
2012-08-23 08:05:07 +08:00
2013-01-31 01:49:25 +08:00
/***/ }
/******/ })
2012-08-23 08:05:07 +08:00
```
# js/[hash].worker.js
``` javascript
2013-01-31 10:25:20 +08:00
/******/ (function webpackBootstrap(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].call(null, module, module.exports, require);
/******/ module.loaded = true;
/******/ return module.exports;
/******/ }
/******/ require.e = function requireEnsure(chunkId, callback) {
/******/ if(installedChunks[chunkId] === 1) return callback.call(null, require);
/******/ importScripts(""+chunkId+".bundle.js");
/******/ callback.call(null, require);
/******/ };
/******/ require.modules = modules;
/******/ require.cache = installedModules;
/******/ var installedChunks = {0:1};
/******/ this["webpackChunk"] = function webpackChunkCallback(moreModules) {
/******/ for(var moduleId in moreModules)
/******/ modules[moduleId] = moreModules[moduleId];
/******/ };
/******/ return require(0);
/******/ })({
/******/ c: "",
2012-08-23 08:05:07 +08:00
2013-01-31 10:25:20 +08:00
/***/ 0:
/*!*******************!*\
!*** ./worker.js ***!
\*******************/
/***/ function(module, exports, require) {
2012-08-23 08:05:07 +08:00
2013-01-31 10:25:20 +08:00
onmessage = function(event) {
var template = event.data;
require.e/* require */(1, function(require) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [require(/*! ../require.context/templates */ 1)("./" + event.data)]; (function(tmpl) {
postMessage(tmpl());
}.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));});
2012-08-23 08:05:07 +08:00
}
2013-01-31 10:25:20 +08:00
2012-10-09 06:12:10 +08:00
2013-01-31 10:25:20 +08:00
/***/ }
/******/ })
2012-08-23 08:05:07 +08:00
```
# Info
## Uncompressed
```
2013-01-31 10:25:20 +08:00
Hash: 457a4d61bec8a96b0716a97eace04243
Time: 71ms
Asset Size Chunks Chunk Names
hash.worker.js 1701
1.hash.worker.js 1424
output.js 1677 0 main
chunk {0} output.js (main) 302
[0] ./example.js 206 [built] {0}
[1] C:/Users/Sokrates/Eigene Repos/webpack-development/~/worker-loader!./worker.js 96 [not cacheable] [built] {0}
2013-01-31 01:49:25 +08:00
cjs require worker!./worker [0] ./example.js 1:13-39
Child worker:
2013-01-31 10:25:20 +08:00
Hash: 68a1c224412cf9f9d63329c7b225e850
Asset Size Chunks Chunk Names
hash.worker.js 1701 0 main
1.hash.worker.js 1424 1
chunk {0} hash.worker.js (main) 168
chunk {1} 1.hash.worker.js 463 {0}
2012-08-23 08:05:07 +08:00
```
## Minimized (uglify-js, no zip)
```
2013-01-31 10:25:20 +08:00
Hash: 457a4d61bec8a96b0716a97eace04243
Time: 196ms
Asset Size Chunks Chunk Names
hash.worker.js 586
1.hash.worker.js 492
output.js 482 0 main
chunk {0} output.js (main) 302
[0] ./example.js 206 [built] {0}
[1] C:/Users/Sokrates/Eigene Repos/webpack-development/~/worker-loader!./worker.js 96 [not cacheable] [built] {0}
2013-01-31 01:49:25 +08:00
cjs require worker!./worker [0] ./example.js 1:13-39
Child worker:
2013-01-31 10:25:20 +08:00
Hash: 68a1c224412cf9f9d63329c7b225e850
Asset Size Chunks Chunk Names
hash.worker.js 586 0 main
1.hash.worker.js 492 1
chunk {0} hash.worker.js (main) 168
chunk {1} 1.hash.worker.js 463 {0}
2012-08-23 08:05:07 +08:00
```