webpack/examples/web-worker/README.md

339 lines
11 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-03-28 17:31:52 +08:00
/******/ (function(modules) { // webpackBootstrap
2013-12-16 06:30:50 +08:00
/******/
2013-03-28 17:31:52 +08:00
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
2014-03-25 17:44:10 +08:00
/******/ function __webpack_require__(moduleId) {
2013-03-28 17:31:52 +08:00
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
2014-03-25 17:44:10 +08:00
/******/ return installedModules[moduleId].exports;
2013-03-28 17:31:52 +08:00
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
2014-03-25 17:44:10 +08:00
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
2013-03-28 17:31:52 +08:00
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
2014-03-25 17:44:10 +08:00
/******/ return module.exports;
2013-03-28 17:31:52 +08:00
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.m = modules;
2013-03-28 17:31:52 +08:00
/******/
/******/ // expose the module cache
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.c = installedModules;
2013-03-28 17:31:52 +08:00
/******/
2013-12-16 06:30:50 +08:00
/******/ // __webpack_public_path__
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.p = "js/";
2013-12-16 06:30:50 +08:00
/******/
2013-03-28 17:31:52 +08:00
/******/
/******/ // Load entry module and return exports
2014-03-25 17:44:10 +08:00
/******/ return __webpack_require__(0);
2013-03-28 17:31:52 +08:00
/******/ })
2013-03-27 01:22:30 +08:00
/************************************************************************/
2013-12-16 06:30:50 +08:00
/******/ ([
/* 0 */
2013-01-31 01:49:25 +08:00
/*!********************!*\
!*** ./example.js ***!
\********************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2013-01-31 01:49:25 +08:00
2014-03-25 17:44:10 +08:00
var Worker = __webpack_require__(/*! worker!./worker */ 1);
2013-03-28 17:20:14 +08:00
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
/***/ },
2013-12-16 06:30:50 +08:00
/* 1 */
2014-01-24 20:33:19 +08:00
/*!*********************************************!*\
2013-02-13 18:58:13 +08:00
!*** (webpack)/~/worker-loader!./worker.js ***!
2014-01-24 20:33:19 +08:00
\*********************************************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2012-08-23 08:05:07 +08:00
2013-03-28 17:20:14 +08:00
module.exports = function() {
2014-03-25 17:44:10 +08:00
return new Worker(__webpack_require__.p + "hash.worker.js");
2013-03-28 17:20:14 +08:00
};
2012-08-23 08:05:07 +08:00
2013-01-31 01:49:25 +08:00
/***/ }
2013-12-16 06:30:50 +08:00
/******/ ])
2012-08-23 08:05:07 +08:00
```
# js/[hash].worker.js
``` javascript
2013-03-28 17:31:52 +08:00
/******/ (function(modules) { // webpackBootstrap
2013-12-16 06:30:50 +08:00
/******/
2013-03-28 17:31:52 +08:00
/******/ // The module cache
/******/ var installedModules = {};
2013-03-28 17:31:52 +08:00
/******/
/******/ // object to store loaded chunks
/******/ // "1" means "already loaded"
2013-12-16 06:30:50 +08:00
/******/ var installedChunks = {
2014-02-12 15:56:54 +08:00
/******/ 1:1
2013-12-16 06:30:50 +08:00
/******/ };
2013-03-28 17:31:52 +08:00
/******/
/******/ // The require function
2014-03-25 17:44:10 +08:00
/******/ function __webpack_require__(moduleId) {
2013-03-28 17:31:52 +08:00
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
2014-03-25 17:44:10 +08:00
/******/ return installedModules[moduleId].exports;
2013-03-28 17:31:52 +08:00
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
2013-03-28 17:31:52 +08:00
/******/
/******/ // Execute the module function
2014-03-25 17:44:10 +08:00
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
2013-03-28 17:31:52 +08:00
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
2013-03-28 17:31:52 +08:00
/******/
/******/ // Return the exports of the module
2014-03-25 17:44:10 +08:00
/******/ return module.exports;
/******/ }
2013-03-28 17:31:52 +08:00
/******/
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
2013-03-28 17:31:52 +08:00
/******/ // "1" is the signal for "already loaded"
/******/ if(!installedChunks[chunkId]) {
/******/ importScripts("" + chunkId + ".hash.worker.js");
/******/ }
2014-03-25 17:44:10 +08:00
/******/ callback.call(null, __webpack_require__);
/******/ };
2013-03-28 17:31:52 +08:00
/******/
/******/ // expose the modules object (__webpack_modules__)
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.m = modules;
2013-03-28 17:31:52 +08:00
/******/
/******/ // expose the module cache
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.c = installedModules;
2013-12-16 06:30:50 +08:00
/******/
/******/ // __webpack_public_path__
2014-03-25 17:44:10 +08:00
/******/ __webpack_require__.p = "";
/******/ this["webpackChunk"] = function webpackChunkCallback(chunkIds, moreModules) {
2013-09-25 04:30:07 +08:00
/******/ for(var moduleId in moreModules) {
/******/ modules[moduleId] = moreModules[moduleId];
2013-09-25 04:30:07 +08:00
/******/ }
2013-03-28 17:31:52 +08:00
/******/ while(chunkIds.length)
/******/ installedChunks[chunkIds.pop()] = 1;
/******/ };
2013-03-28 17:31:52 +08:00
/******/
/******/ // Load entry module and return exports
2014-03-25 17:44:10 +08:00
/******/ return __webpack_require__(0);
2013-03-28 17:31:52 +08:00
/******/ })
/************************************************************************/
2013-12-16 06:30:50 +08:00
/******/ ([
/* 0 */
2013-01-31 10:25:20 +08:00
/*!*******************!*\
!*** ./worker.js ***!
\*******************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2012-08-23 08:05:07 +08:00
2013-03-28 17:20:14 +08:00
onmessage = function(event) {
var template = event.data;
2014-03-25 17:44:10 +08:00
__webpack_require__.e/* require */(0, function(__webpack_require__) { var __WEBPACK_AMD_REQUIRE_ARRAY__ = [__webpack_require__(/*! ../require.context/templates */ 4)("./" + event.data)]; (function(tmpl) {
2013-03-28 17:20:14 +08:00
postMessage(tmpl());
}.apply(null, __WEBPACK_AMD_REQUIRE_ARRAY__));});
}
2013-10-31 07:49:59 +08:00
2012-08-23 08:05:07 +08:00
2013-03-27 01:22:30 +08:00
/***/ }
2013-12-16 06:30:50 +08:00
/******/ ])
2012-08-23 08:05:07 +08:00
```
2014-02-12 15:56:54 +08:00
# js/0.[hash].worker.hs
``` javascript
2014-02-12 15:56:54 +08:00
webpackChunk([0],[
2013-12-16 06:30:50 +08:00
/* 0 */,
/* 1 */
/*!*****************************************!*\
!*** ../require.context/templates/a.js ***!
\*****************************************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2013-03-28 17:20:14 +08:00
module.exports = function() {
return "This text was generated by template A";
}
/***/ },
/* 2 */
/*!*****************************************!*\
!*** ../require.context/templates/b.js ***!
\*****************************************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2013-03-28 17:20:14 +08:00
module.exports = function() {
return "This text was generated by template B";
}
/***/ },
/* 3 */
/*!*****************************************!*\
!*** ../require.context/templates/c.js ***!
\*****************************************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
2013-03-28 17:20:14 +08:00
module.exports = function() {
return "This text was generated by template C";
}
/***/ },
/* 4 */
/*!*********************************************!*\
!*** ../require.context/templates ^\.\/.*$ ***!
\*********************************************/
2014-03-25 17:44:10 +08:00
/***/ function(module, exports, __webpack_require__) {
var map = {
"./a": 1,
"./a.js": 1,
"./b": 2,
"./b.js": 2,
"./c": 3,
"./c.js": 3
};
function webpackContext(req) {
2014-03-25 17:44:10 +08:00
return __webpack_require__(webpackContextResolve(req));
};
function webpackContextResolve(req) {
return map[req] || (function() { throw new Error("Cannot find module '" + req + "'.") }());
};
webpackContext.keys = function webpackContextKeys() {
return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
/***/ }
2013-12-16 06:30:50 +08:00
])
```
2012-08-23 08:05:07 +08:00
# Info
## Uncompressed
```
2014-01-24 20:33:19 +08:00
Hash: d3a484ec9964172dc379
2014-03-25 17:44:10 +08:00
Version: webpack 1.1.0
Time: 108ms
2013-05-08 21:36:54 +08:00
Asset Size Chunks Chunk Names
2014-03-25 17:44:10 +08:00
0.hash.worker.js 1653 [emitted]
hash.worker.js 2831 [emitted]
output.js 2167 0 [emitted] main
2013-09-25 04:30:07 +08:00
chunk {0} output.js (main) 302 [rendered]
2014-03-25 17:44:10 +08:00
> main [0] ./example.js
2013-09-25 04:30:07 +08:00
[0] ./example.js 206 {0} [built]
[1] (webpack)/~/worker-loader!./worker.js 96 {0} [not cacheable] [built]
2013-01-31 01:49:25 +08:00
cjs require worker!./worker [0] ./example.js 1:13-39
Child worker:
2014-02-12 15:56:54 +08:00
Hash: 374188a31a72007585d1
2014-03-25 17:44:10 +08:00
Version: webpack 1.1.0
2013-05-08 21:36:54 +08:00
Asset Size Chunks Chunk Names
2014-03-25 17:44:10 +08:00
0.hash.worker.js 1653 0 [emitted]
hash.worker.js 2831 1 [emitted] main
2014-02-12 15:56:54 +08:00
chunk {0} 0.hash.worker.js 463 {1} [rendered]
2014-01-24 20:33:19 +08:00
> [0] ./worker.js 3:1-5:3
2014-02-12 15:56:54 +08:00
[1] ../require.context/templates/a.js 82 {0} [built]
context element ./a.js [4] ../require.context/templates ^\.\/.*$
context element ./a [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[2] ../require.context/templates/b.js 82 {0} [built]
context element ./b.js [4] ../require.context/templates ^\.\/.*$
context element ./b [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[3] ../require.context/templates/c.js 82 {0} [built]
context element ./c.js [4] ../require.context/templates ^\.\/.*$
context element ./c [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[4] ../require.context/templates ^\.\/.*$ 217 {0} [built]
2013-02-13 18:58:13 +08:00
amd require context ../require.context/templates [0] ./worker.js 3:1-5:3
2014-02-12 15:56:54 +08:00
chunk {1} hash.worker.js (main) 168 [rendered]
2014-03-25 17:44:10 +08:00
> main [0] ./worker.js
2014-02-12 15:56:54 +08:00
[0] ./worker.js 168 {1} [built]
2012-08-23 08:05:07 +08:00
```
## Minimized (uglify-js, no zip)
```
2014-03-25 17:44:10 +08:00
Hash: e028e5c3f2a9ee017ccf
Version: webpack 1.1.0
Time: 235ms
2013-05-08 21:36:54 +08:00
Asset Size Chunks Chunk Names
2014-02-12 15:56:54 +08:00
0.hash.worker.js 528 [emitted]
2014-03-25 17:44:10 +08:00
hash.worker.js 513 [emitted]
output.js 371 0 [emitted] main
2013-09-25 04:30:07 +08:00
chunk {0} output.js (main) 302 [rendered]
2014-03-25 17:44:10 +08:00
> main [0] ./example.js
2013-09-25 04:30:07 +08:00
[0] ./example.js 206 {0} [built]
[1] (webpack)/~/worker-loader!./worker.js 96 {0} [not cacheable] [built]
2013-01-31 01:49:25 +08:00
cjs require worker!./worker [0] ./example.js 1:13-39
2013-09-25 04:30:07 +08:00
WARNING in output.js from UglifyJs
Side effects in initialization of unused variable templateB [./example.js:5,0]
2013-01-31 01:49:25 +08:00
Child worker:
2014-03-25 17:44:10 +08:00
Hash: f557b852479205b3c82c
Version: webpack 1.1.0
2013-05-08 21:36:54 +08:00
Asset Size Chunks Chunk Names
2014-02-12 15:56:54 +08:00
0.hash.worker.js 528 0 [emitted]
2014-03-25 17:44:10 +08:00
hash.worker.js 513 1 [emitted] main
2014-02-12 15:56:54 +08:00
chunk {0} 0.hash.worker.js 463 {1} [rendered]
2014-01-24 20:33:19 +08:00
> [0] ./worker.js 3:1-5:3
2014-02-12 15:56:54 +08:00
[1] ../require.context/templates/a.js 82 {0} [built]
context element ./a.js [4] ../require.context/templates ^\.\/.*$
context element ./a [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[2] ../require.context/templates/b.js 82 {0} [built]
context element ./b.js [4] ../require.context/templates ^\.\/.*$
context element ./b [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[3] ../require.context/templates/c.js 82 {0} [built]
context element ./c.js [4] ../require.context/templates ^\.\/.*$
context element ./c [4] ../require.context/templates ^\.\/.*$
2014-02-12 15:56:54 +08:00
[4] ../require.context/templates ^\.\/.*$ 217 {0} [built]
2013-02-13 18:58:13 +08:00
amd require context ../require.context/templates [0] ./worker.js 3:1-5:3
2014-02-12 15:56:54 +08:00
chunk {1} hash.worker.js (main) 168 [rendered]
2014-03-25 17:44:10 +08:00
> main [0] ./worker.js
2014-02-12 15:56:54 +08:00
[0] ./worker.js 168 {1} [built]
2013-09-25 04:30:07 +08:00
WARNING in hash.worker.js from UglifyJs
Side effects in initialization of unused variable template [./worker.js:2,0]
2012-08-23 08:05:07 +08:00
```