From 15c0160787dea246f57ac49eea89a54ea6844d2d Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 27 Jul 2017 13:52:38 +0200 Subject: [PATCH] add dll-app-and-vendor example by @aretecode --- .../dll-app-and-vendor/0-vendor/README.md | 185 ++++++++++++++++ examples/dll-app-and-vendor/0-vendor/build.js | 2 + .../0-vendor/js/vendor-manifest.json | 1 + .../dll-app-and-vendor/0-vendor/js/vendor.js | 96 ++++++++ .../dll-app-and-vendor/0-vendor/template.md | 46 ++++ .../0-vendor/webpack.config.js | 18 ++ examples/dll-app-and-vendor/1-app/README.md | 209 ++++++++++++++++++ examples/dll-app-and-vendor/1-app/build.js | 2 + .../dll-app-and-vendor/1-app/example-app.js | 4 + .../dll-app-and-vendor/1-app/example.html | 7 + examples/dll-app-and-vendor/1-app/js/app.js | 107 +++++++++ examples/dll-app-and-vendor/1-app/template.md | 47 ++++ .../1-app/webpack.config.js | 17 ++ examples/dll-app-and-vendor/README.md | 9 + .../node_modules/example-vendor.js | 3 + 15 files changed, 753 insertions(+) create mode 100644 examples/dll-app-and-vendor/0-vendor/README.md create mode 100644 examples/dll-app-and-vendor/0-vendor/build.js create mode 100644 examples/dll-app-and-vendor/0-vendor/js/vendor-manifest.json create mode 100644 examples/dll-app-and-vendor/0-vendor/js/vendor.js create mode 100644 examples/dll-app-and-vendor/0-vendor/template.md create mode 100644 examples/dll-app-and-vendor/0-vendor/webpack.config.js create mode 100644 examples/dll-app-and-vendor/1-app/README.md create mode 100644 examples/dll-app-and-vendor/1-app/build.js create mode 100644 examples/dll-app-and-vendor/1-app/example-app.js create mode 100644 examples/dll-app-and-vendor/1-app/example.html create mode 100644 examples/dll-app-and-vendor/1-app/js/app.js create mode 100644 examples/dll-app-and-vendor/1-app/template.md create mode 100644 examples/dll-app-and-vendor/1-app/webpack.config.js create mode 100644 examples/dll-app-and-vendor/README.md create mode 100644 examples/dll-app-and-vendor/node_modules/example-vendor.js diff --git a/examples/dll-app-and-vendor/0-vendor/README.md b/examples/dll-app-and-vendor/0-vendor/README.md new file mode 100644 index 000000000..5130052d5 --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/README.md @@ -0,0 +1,185 @@ +This is the vendor build part. + +It's built separatly from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle. + +The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target enviroment. + +A manifest is creates which includes mappings from module names to internal ids. + +### webpack.config.js + +``` javascript +var path = require("path"); +var webpack = require("../../../"); + +module.exports = { + context: __dirname, + entry: ["example-vendor"], + output: { + filename: "vendor.js", // best use [hash] here too + path: path.resolve(__dirname, "js"), + library: "vendor_lib_[hash]", + }, + plugins: [ + new webpack.DllPlugin({ + name: "vendor_lib_[hash]", + path: path.resolve(__dirname, "js/vendor-manifest.json"), + }), + ], +}; +``` + +# example-vendor + +``` javascript +export function square(n) { + return n * n; +} +``` + +# js/vendor.js + +``` javascript +var vendor_lib_6b1edee0549eb5092709 = +``` +
/******/ (function(modules) { /* webpackBootstrap */ }) + +``` js +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // 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 +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // 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; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "js/"; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +``` + +
+ +``` js +/******/ ([ +/* 0 */ +/*!****************!*\ + !*** dll main ***! + \****************/ +/*! no static exports found */ +/*! all exports used */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__; + +/***/ }), +/* 1 */ +/*!*****************************************!*\ + !*** ../node_modules/example-vendor.js ***! + \*****************************************/ +/*! exports provided: square */ +/*! all exports used */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +/* harmony export (immutable) */ __webpack_exports__["square"] = square; +function square(n) { + return n * n; +} + + +/***/ }) +/******/ ]); +``` + +# js/vendor-manifest.json + +``` javascript +{"name":"vendor_lib_6b1edee0549eb5092709","content":{"../node_modules/example-vendor.js":{"id":1,"meta":{"harmonyModule":true},"exports":["square"]}}} +``` + +# Info + +## Uncompressed + +``` +Hash: 6b1edee0549eb5092709 +Version: webpack 3.4.1 + Asset Size Chunks Chunk Names +vendor.js 3.18 kB 0 [emitted] main +Entrypoint main = vendor.js +chunk {0} vendor.js (main) 60 bytes [entry] [rendered] + > main [0] dll main + [0] dll main 12 bytes {0} [built] + + 1 hidden module +``` + +## Minimized (uglify-js, no zip) + +``` +Hash: 6b1edee0549eb5092709 +Version: webpack 3.4.1 + Asset Size Chunks Chunk Names +vendor.js 652 bytes 0 [emitted] main +Entrypoint main = vendor.js +chunk {0} vendor.js (main) 60 bytes [entry] [rendered] + > main [0] dll main + [0] dll main 12 bytes {0} [built] + + 1 hidden module +``` + diff --git a/examples/dll-app-and-vendor/0-vendor/build.js b/examples/dll-app-and-vendor/0-vendor/build.js new file mode 100644 index 000000000..21ec90edf --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/build.js @@ -0,0 +1,2 @@ +global.NO_TARGET_ARGS = true; +require("../../build-common"); diff --git a/examples/dll-app-and-vendor/0-vendor/js/vendor-manifest.json b/examples/dll-app-and-vendor/0-vendor/js/vendor-manifest.json new file mode 100644 index 000000000..134336962 --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/js/vendor-manifest.json @@ -0,0 +1 @@ +{"name":"vendor_lib_6b1edee0549eb5092709","content":{"../node_modules/example-vendor.js":{"id":1,"meta":{"harmonyModule":true},"exports":["square"]}}} \ No newline at end of file diff --git a/examples/dll-app-and-vendor/0-vendor/js/vendor.js b/examples/dll-app-and-vendor/0-vendor/js/vendor.js new file mode 100644 index 000000000..e93c673af --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/js/vendor.js @@ -0,0 +1,96 @@ +var vendor_lib_6b1edee0549eb5092709 = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // 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 +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // 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; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "js/"; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/*!****************!*\ + !*** dll main ***! + \****************/ +/*! no static exports found */ +/*! all exports used */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = __webpack_require__; + +/***/ }), +/* 1 */ +/*!*****************************************!*\ + !*** ../node_modules/example-vendor.js ***! + \*****************************************/ +/*! exports provided: square */ +/*! all exports used */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +/* harmony export (immutable) */ __webpack_exports__["square"] = square; +function square(n) { + return n * n; +} + + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/examples/dll-app-and-vendor/0-vendor/template.md b/examples/dll-app-and-vendor/0-vendor/template.md new file mode 100644 index 000000000..140b1fbe0 --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/template.md @@ -0,0 +1,46 @@ +This is the vendor build part. + +It's built separatly from the app part. The vendors dll is only built when vendors has changed and not while the normal development cycle. + +The DllPlugin in combination with the `output.library` option exposes the internal require function as global variable in the target enviroment. + +A manifest is creates which includes mappings from module names to internal ids. + +### webpack.config.js + +``` javascript +{{webpack.config.js}} +``` + +# example-vendor + +``` javascript +{{../node_modules/example-vendor.js}} +``` + +# js/vendor.js + +``` javascript +{{js/vendor.js}} +``` + +# js/vendor-manifest.json + +``` javascript +{{js/vendor-manifest.json}} +``` + +# Info + +## Uncompressed + +``` +{{stdout}} +``` + +## Minimized (uglify-js, no zip) + +``` +{{min:stdout}} +``` + diff --git a/examples/dll-app-and-vendor/0-vendor/webpack.config.js b/examples/dll-app-and-vendor/0-vendor/webpack.config.js new file mode 100644 index 000000000..89b48fa5e --- /dev/null +++ b/examples/dll-app-and-vendor/0-vendor/webpack.config.js @@ -0,0 +1,18 @@ +var path = require("path"); +var webpack = require("../../../"); + +module.exports = { + context: __dirname, + entry: ["example-vendor"], + output: { + filename: "vendor.js", // best use [hash] here too + path: path.resolve(__dirname, "js"), + library: "vendor_lib_[hash]", + }, + plugins: [ + new webpack.DllPlugin({ + name: "vendor_lib_[hash]", + path: path.resolve(__dirname, "js/vendor-manifest.json"), + }), + ], +}; diff --git a/examples/dll-app-and-vendor/1-app/README.md b/examples/dll-app-and-vendor/1-app/README.md new file mode 100644 index 000000000..cab36c41c --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/README.md @@ -0,0 +1,209 @@ +This is the app part. + +The previously built vendor dll is used. The DllReferencePlugin reads the content of the dll from the manifest file and excludes all vendor modules from the compilation. Instead references to these modules will be loaded from the vendor dll via a global variable (`vendor_lib_xxxx`). + +# webpack.config.js + +``` javascript +var path = require("path"); +var webpack = require("../../../"); + +module.exports = { + context: __dirname, + entry: "./example-app", + output: { + filename: "app.js", + path: path.resolve(__dirname, "js"), + }, + plugins: [ + new webpack.DllReferencePlugin({ + context: ".", + manifest: require("../0-vendor/js/vendor-manifest.json"), // eslint-disable-line + }), + ], +}; +``` + +# example-app.js + +``` javascript +import { square } from "example-vendor"; + +console.log(square(7)); +console.log(new square(7)); +``` + +# example.html + +``` html + + + + + + + +``` + +# js/app.js + +
/******/ (function(modules) { /* webpackBootstrap */ }) + +``` javascript +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // 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 +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // 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; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "js/"; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +``` + +
+ +``` javascript +/******/ ([ +/* 0 */ +/*!************************!*\ + !*** ./example-app.js ***! + \************************/ +/*! exports provided: */ +/*! all exports used */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_example_vendor__ = __webpack_require__(/*! example-vendor */ 1); + + +console.log(Object(__WEBPACK_IMPORTED_MODULE_0_example_vendor__["square"])(7)); +console.log(new __WEBPACK_IMPORTED_MODULE_0_example_vendor__["square"](7)); + + +/***/ }), +/* 1 */ +/*!******************************************************************************************************!*\ + !*** delegated ../node_modules/example-vendor.js from dll-reference vendor_lib_6b1edee0549eb5092709 ***! + \******************************************************************************************************/ +/*! exports provided: square */ +/*! all exports used */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = (__webpack_require__(2))(1); + +/***/ }), +/* 2 */ +/*!**************************************************!*\ + !*** external "vendor_lib_6b1edee0549eb5092709" ***! + \**************************************************/ +/*! no static exports found */ +/*! all exports used */ +/***/ (function(module, exports) { + +module.exports = vendor_lib_6b1edee0549eb5092709; + +/***/ }) +/******/ ]); +``` + +# Info + +## Uncompressed + +``` +Hash: 26778169dabaf1f3965d +Version: webpack 3.4.1 + Asset Size Chunks Chunk Names +app.js 3.85 kB 0 [emitted] main +Entrypoint main = app.js +chunk {0} app.js (main) 182 bytes [entry] [rendered] + > main [0] ./example-app.js + [0] ./example-app.js 98 bytes {0} [built] + [no exports] + [1] delegated ../node_modules/example-vendor.js from dll-reference vendor_lib_6b1edee0549eb5092709 42 bytes {0} [built] + [exports: square] + harmony import example-vendor [0] ./example-app.js 1:0-40 + + 1 hidden module +``` + +## Minimized (uglify-js, no zip) + +``` +Hash: 26778169dabaf1f3965d +Version: webpack 3.4.1 + Asset Size Chunks Chunk Names +app.js 710 bytes 0 [emitted] main +Entrypoint main = app.js +chunk {0} app.js (main) 182 bytes [entry] [rendered] + > main [0] ./example-app.js + [0] ./example-app.js 98 bytes {0} [built] + [no exports] + [1] delegated ../node_modules/example-vendor.js from dll-reference vendor_lib_6b1edee0549eb5092709 42 bytes {0} [built] + [exports: square] + harmony import example-vendor [0] ./example-app.js 1:0-40 + + 1 hidden module +``` + + diff --git a/examples/dll-app-and-vendor/1-app/build.js b/examples/dll-app-and-vendor/1-app/build.js new file mode 100644 index 000000000..21ec90edf --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/build.js @@ -0,0 +1,2 @@ +global.NO_TARGET_ARGS = true; +require("../../build-common"); diff --git a/examples/dll-app-and-vendor/1-app/example-app.js b/examples/dll-app-and-vendor/1-app/example-app.js new file mode 100644 index 000000000..a2fb8e0a9 --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/example-app.js @@ -0,0 +1,4 @@ +import { square } from "example-vendor"; + +console.log(square(7)); +console.log(new square(7)); diff --git a/examples/dll-app-and-vendor/1-app/example.html b/examples/dll-app-and-vendor/1-app/example.html new file mode 100644 index 000000000..84c2fe2f6 --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/example.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/examples/dll-app-and-vendor/1-app/js/app.js b/examples/dll-app-and-vendor/1-app/js/app.js new file mode 100644 index 000000000..d155147bc --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/js/app.js @@ -0,0 +1,107 @@ +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // 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 +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // 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; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = "js/"; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = 0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/*!************************!*\ + !*** ./example-app.js ***! + \************************/ +/*! exports provided: */ +/*! all exports used */ +/***/ (function(module, __webpack_exports__, __webpack_require__) { + +"use strict"; +Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); +/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_example_vendor__ = __webpack_require__(/*! example-vendor */ 1); + + +console.log(Object(__WEBPACK_IMPORTED_MODULE_0_example_vendor__["square"])(7)); +console.log(new __WEBPACK_IMPORTED_MODULE_0_example_vendor__["square"](7)); + + +/***/ }), +/* 1 */ +/*!******************************************************************************************************!*\ + !*** delegated ../node_modules/example-vendor.js from dll-reference vendor_lib_6b1edee0549eb5092709 ***! + \******************************************************************************************************/ +/*! exports provided: square */ +/*! all exports used */ +/***/ (function(module, exports, __webpack_require__) { + +module.exports = (__webpack_require__(2))(1); + +/***/ }), +/* 2 */ +/*!**************************************************!*\ + !*** external "vendor_lib_6b1edee0549eb5092709" ***! + \**************************************************/ +/*! no static exports found */ +/*! all exports used */ +/***/ (function(module, exports) { + +module.exports = vendor_lib_6b1edee0549eb5092709; + +/***/ }) +/******/ ]); \ No newline at end of file diff --git a/examples/dll-app-and-vendor/1-app/template.md b/examples/dll-app-and-vendor/1-app/template.md new file mode 100644 index 000000000..48e472930 --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/template.md @@ -0,0 +1,47 @@ +This is the app part. + +The previously built vendor dll is used. The DllReferencePlugin reads the content of the dll from the manifest file and excludes all vendor modules from the compilation. Instead references to these modules will be loaded from the vendor dll via a global variable (`vendor_lib_xxxx`). + +# webpack.config.js + +``` javascript +{{webpack.config.js}} +``` + +# example-app.js + +``` javascript +{{example-app.js}} +``` + +# example.html + +``` html +{{example.html}} +``` + +# js/app.js + +``` javascript +{{js/app.js}} +``` + +# Info + +## Uncompressed + +``` +{{stdout}} +``` + +## Minimized (uglify-js, no zip) + +``` +{{min:stdout}} +``` + + diff --git a/examples/dll-app-and-vendor/1-app/webpack.config.js b/examples/dll-app-and-vendor/1-app/webpack.config.js new file mode 100644 index 000000000..2a02109d0 --- /dev/null +++ b/examples/dll-app-and-vendor/1-app/webpack.config.js @@ -0,0 +1,17 @@ +var path = require("path"); +var webpack = require("../../../"); + +module.exports = { + context: __dirname, + entry: "./example-app", + output: { + filename: "app.js", + path: path.resolve(__dirname, "js"), + }, + plugins: [ + new webpack.DllReferencePlugin({ + context: ".", + manifest: require("../0-vendor/js/vendor-manifest.json"), // eslint-disable-line + }), + ], +}; diff --git a/examples/dll-app-and-vendor/README.md b/examples/dll-app-and-vendor/README.md new file mode 100644 index 000000000..a4e937031 --- /dev/null +++ b/examples/dll-app-and-vendor/README.md @@ -0,0 +1,9 @@ +This example shows how to use the DllPlugin to separate vendor and app build. + +This can boost the speed of the app build because vendors are no longer included, but built separately. + +See [vendor part](0-vendor) and [app part](1-app). + +[DllPlugin documentation](https://webpack.js.org/plugins/dll-plugin) + +> Based on this gist: https://gist.github.com/Eoksni/83d1f1559e0ec00d0e89c33a6d763049 by Eoksni diff --git a/examples/dll-app-and-vendor/node_modules/example-vendor.js b/examples/dll-app-and-vendor/node_modules/example-vendor.js new file mode 100644 index 000000000..a7c4f4329 --- /dev/null +++ b/examples/dll-app-and-vendor/node_modules/example-vendor.js @@ -0,0 +1,3 @@ +export function square(n) { + return n * n; +}