2016-12-14 19:03:24 +08:00
|
|
|
# webpack.config.js
|
|
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
|
var path = require("path");
|
|
|
|
|
module.exports = {
|
|
|
|
|
entry: "./example",
|
|
|
|
|
output: {
|
|
|
|
|
path: path.join(__dirname, "js"),
|
|
|
|
|
filename: "MyLibrary.umd.js",
|
|
|
|
|
library: "MyLibrary",
|
|
|
|
|
libraryTarget: "umd"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# js/MyLibrary.umd.js
|
|
|
|
|
|
|
|
|
|
``` javascript
|
|
|
|
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
|
|
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
|
|
|
module.exports = factory();
|
|
|
|
|
else if(typeof define === 'function' && define.amd)
|
|
|
|
|
define([], factory);
|
|
|
|
|
else if(typeof exports === 'object')
|
|
|
|
|
exports["MyLibrary"] = factory();
|
|
|
|
|
else
|
|
|
|
|
root["MyLibrary"] = factory();
|
|
|
|
|
})(this, function() {
|
|
|
|
|
```
|
2017-03-31 02:42:42 +08:00
|
|
|
<details><summary><code>return /******/ (function(modules) { /* webpackBootstrap */ })</code></summary>
|
|
|
|
|
|
2016-12-14 19:03:24 +08:00
|
|
|
``` js
|
|
|
|
|
return /******/ (function(modules) { // webpackBootstrap
|
|
|
|
|
/******/ // The module cache
|
|
|
|
|
/******/ var installedModules = {};
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // The require function
|
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Check if module is in cache
|
2017-05-23 04:45:18 +08:00
|
|
|
/******/ if(installedModules[moduleId]) {
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ return installedModules[moduleId].exports;
|
2017-05-23 04:45:18 +08:00
|
|
|
/******/ }
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
|
/******/ i: moduleId,
|
|
|
|
|
/******/ l: false,
|
|
|
|
|
/******/ exports: {}
|
|
|
|
|
/******/ };
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Execute the module function
|
|
|
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
|
/******/ module.l = true;
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Return the exports of the module
|
|
|
|
|
/******/ return module.exports;
|
|
|
|
|
/******/ }
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
|
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
|
|
|
/******/ __webpack_require__.m = modules;
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // expose the module cache
|
|
|
|
|
/******/ __webpack_require__.c = installedModules;
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // define getter function for harmony exports
|
|
|
|
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
|
|
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
|
|
|
/******/ Object.defineProperty(exports, name, {
|
|
|
|
|
/******/ configurable: false,
|
|
|
|
|
/******/ enumerable: true,
|
|
|
|
|
/******/ get: getter
|
|
|
|
|
/******/ });
|
|
|
|
|
/******/ }
|
|
|
|
|
/******/ };
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
|
|
|
/******/ __webpack_require__.n = function(module) {
|
|
|
|
|
/******/ var getter = module && module.__esModule ?
|
|
|
|
|
/******/ function getDefault() { return module['default']; } :
|
|
|
|
|
/******/ function getModuleExports() { return module; };
|
|
|
|
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
|
|
|
/******/ return getter;
|
|
|
|
|
/******/ };
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Object.prototype.hasOwnProperty.call
|
|
|
|
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // __webpack_public_path__
|
|
|
|
|
/******/ __webpack_require__.p = "js/";
|
2017-03-31 02:25:01 +08:00
|
|
|
/******/
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ // Load entry module and return exports
|
|
|
|
|
/******/ return __webpack_require__(__webpack_require__.s = 0);
|
|
|
|
|
/******/ })
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
```
|
2017-03-31 02:42:42 +08:00
|
|
|
|
2016-12-14 19:03:24 +08:00
|
|
|
</details>
|
2017-03-31 02:42:42 +08:00
|
|
|
|
2016-12-14 19:03:24 +08:00
|
|
|
``` js
|
|
|
|
|
/******/ ([
|
|
|
|
|
/* 0 */
|
|
|
|
|
/*!********************!*\
|
|
|
|
|
!*** ./example.js ***!
|
|
|
|
|
\********************/
|
2017-06-05 22:12:12 +08:00
|
|
|
/*! exports provided: value, increment, default */
|
|
|
|
|
/*! all exports used */
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
2016-12-14 19:03:24 +08:00
|
|
|
|
|
|
|
|
"use strict";
|
2017-03-31 02:25:01 +08:00
|
|
|
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
|
|
|
|
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "value", function() { return value; });
|
2017-11-23 16:47:19 +08:00
|
|
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "increment", function() { return increment; });
|
2016-12-14 19:03:24 +08:00
|
|
|
var value = 0;
|
|
|
|
|
function increment() {
|
|
|
|
|
value++;
|
|
|
|
|
}
|
2017-03-31 02:25:01 +08:00
|
|
|
/* harmony default export */ __webpack_exports__["default"] = ("MyLibrary");
|
2016-12-14 19:03:24 +08:00
|
|
|
|
|
|
|
|
|
2017-03-31 02:25:01 +08:00
|
|
|
/***/ })
|
2016-12-14 19:03:24 +08:00
|
|
|
/******/ ]);
|
|
|
|
|
});
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# Info
|
|
|
|
|
|
|
|
|
|
## Uncompressed
|
|
|
|
|
|
|
|
|
|
```
|
2017-11-23 16:47:19 +08:00
|
|
|
Hash: 3644f1adc4c521a71110
|
|
|
|
|
Version: webpack next
|
|
|
|
|
Asset Size Chunks Chunk Names
|
|
|
|
|
MyLibrary.umd.js 3.41 KiB 0 [emitted] main
|
2016-12-14 19:03:24 +08:00
|
|
|
Entrypoint main = MyLibrary.umd.js
|
|
|
|
|
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
|
|
|
|
|
> main [0] ./example.js
|
|
|
|
|
[0] ./example.js 97 bytes {0} [built]
|
|
|
|
|
[exports: value, increment, default]
|
2017-11-23 16:47:19 +08:00
|
|
|
single entry ./example main
|
2016-12-14 19:03:24 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Minimized (uglify-js, no zip)
|
|
|
|
|
|
|
|
|
|
```
|
2017-11-23 16:47:19 +08:00
|
|
|
Hash: 3644f1adc4c521a71110
|
|
|
|
|
Version: webpack next
|
2016-12-14 19:03:24 +08:00
|
|
|
Asset Size Chunks Chunk Names
|
2017-11-23 16:47:19 +08:00
|
|
|
MyLibrary.umd.js 898 bytes 0 [emitted] main
|
2016-12-14 19:03:24 +08:00
|
|
|
Entrypoint main = MyLibrary.umd.js
|
|
|
|
|
chunk {0} MyLibrary.umd.js (main) 97 bytes [entry] [rendered]
|
|
|
|
|
> main [0] ./example.js
|
|
|
|
|
[0] ./example.js 97 bytes {0} [built]
|
|
|
|
|
[exports: value, increment, default]
|
2017-11-23 16:47:19 +08:00
|
|
|
single entry ./example main
|
2016-12-14 19:03:24 +08:00
|
|
|
```
|