This example uses the I18nPlugin in combination with the multi-compiler feature.
The webpack.config.js exports an array of all config combinations that should be compiled. In this example two different parameters for the I18nPlugin are used.
The I18nPlugin replaces every occurrence of the i18n function __(...) with a const string. i. e. __("Hello World") with "Hello World" resp. "Hallo Welt".
console.log(__("Hello World")); console.log(__("Missing Text"));var path = require("path"); var I18nPlugin = require("i18n-webpack-plugin"); var languages = { "en": null, "de": require("./de.json") }; module.exports = Object.keys(languages).map(function(language) { return { name: language, entry: "./example", output: { path: path.join(__dirname, "js"), filename: language + ".output.js" }, plugins: [ new I18nPlugin( languages[language] ) ] }; });{ "Hello World": "Hallo Welt" }/******/ (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] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = 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; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "js/"; /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /*!********************!*\ !*** ./example.js ***! \********************/ /***/ function(module, exports, __webpack_require__) { console.log("Hallo Welt"); console.log("Missing Text"); /***/ } /******/ ]);/******/ (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] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = 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; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = "js/"; /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /*!********************!*\ !*** ./example.js ***! \********************/ /***/ function(module, exports, __webpack_require__) { console.log("Hello World"); console.log("Missing Text"); /***/ } /******/ ]);Hash: 8376e07a0433da19dc73e2c5e5181623bc3405eb Version: webpack 2.0.6-beta Child en: Hash: 8376e07a0433da19dc73 Version: webpack 2.0.6-beta Time: 71ms Asset Size Chunks Chunk Names en.output.js 1.57 kB 0 [emitted] main chunk {0} en.output.js (main) 65 bytes [rendered] > main [0] ./example.js [0] ./example.js 65 bytes {0} [built] Child de: Hash: e2c5e5181623bc3405eb Version: webpack 2.0.6-beta Time: 62ms Asset Size Chunks Chunk Names de.output.js 1.57 kB 0 [emitted] main chunk {0} de.output.js (main) 65 bytes [rendered] > main [0] ./example.js [0] ./example.js 65 bytes {0} [built] [1 warning] WARNING in ./example.js Missing localization: Missing Text Hash: 8376e07a0433da19dc73e2c5e5181623bc3405eb Version: webpack 2.0.6-beta Child en: Hash: 8376e07a0433da19dc73 Version: webpack 2.0.6-beta Time: 145ms Asset Size Chunks Chunk Names en.output.js 281 bytes 0 [emitted] main chunk {0} en.output.js (main) 65 bytes [rendered] > main [0] ./example.js [0] ./example.js 65 bytes {0} [built] Child de: Hash: e2c5e5181623bc3405eb Version: webpack 2.0.6-beta Time: 136ms Asset Size Chunks Chunk Names de.output.js 280 bytes 0 [emitted] main chunk {0} de.output.js (main) 65 bytes [rendered] > main [0] ./example.js [0] ./example.js 65 bytes {0} [built] [1 warning] WARNING in ./example.js Missing localization: Missing Text