mirror of https://github.com/webpack/webpack.git
added multi compiler example
This commit is contained in:
parent
b0caa69ae1
commit
ce3a2cb8da
|
|
@ -0,0 +1,243 @@
|
|||
|
||||
# example.js
|
||||
|
||||
``` javascript
|
||||
if(ENV === "mobile") {
|
||||
require("./mobile-stuff");
|
||||
}
|
||||
console.log("Running " + ENV + " build");
|
||||
```
|
||||
|
||||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
var path = require("path");
|
||||
var webpack = require("../../");
|
||||
module.exports = [
|
||||
{
|
||||
entry: "./example",
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "mobile.js"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
ENV: JSON.stringify("mobile")
|
||||
})
|
||||
]
|
||||
},
|
||||
{
|
||||
entry: "./example",
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "desktop.js"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
ENV: JSON.stringify("desktop")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
||||
```
|
||||
|
||||
# js/desktop.js
|
||||
|
||||
``` 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] = {
|
||||
/******/ 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__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/*!********************!*\
|
||||
!*** ./example.js ***!
|
||||
\********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
if(false) {
|
||||
require("./mobile-stuff");
|
||||
}
|
||||
console.log("Running " + ("desktop") + " build");
|
||||
|
||||
/***/ }
|
||||
/******/ ])
|
||||
```
|
||||
|
||||
# js/mobile.js
|
||||
|
||||
``` 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] = {
|
||||
/******/ 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__(0);
|
||||
/******/ })
|
||||
/************************************************************************/
|
||||
/******/ ([
|
||||
/* 0 */
|
||||
/*!********************!*\
|
||||
!*** ./example.js ***!
|
||||
\********************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
if(true) {
|
||||
__webpack_require__(/*! ./mobile-stuff */ 1);
|
||||
}
|
||||
console.log("Running " + ("mobile") + " build");
|
||||
|
||||
/***/ },
|
||||
/* 1 */
|
||||
/*!*************************!*\
|
||||
!*** ./mobile-stuff.js ***!
|
||||
\*************************/
|
||||
/***/ function(module, exports, __webpack_require__) {
|
||||
|
||||
// mobile only stuff
|
||||
|
||||
/***/ }
|
||||
/******/ ])
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
Hash: d6e452828343eb86930778c68edab053f09ed9ab
|
||||
Version: webpack 1.3.0-beta6
|
||||
Child
|
||||
Hash: d6e452828343eb869307
|
||||
Version: webpack 1.3.0-beta6
|
||||
Time: 173ms
|
||||
Asset Size Chunks Chunk Names
|
||||
mobile.js 1878 0 [emitted] main
|
||||
chunk {0} mobile.js (main) 117 [rendered]
|
||||
> main [0] ./example.js
|
||||
[0] ./example.js 97 {0} [built]
|
||||
[1] ./mobile-stuff.js 20 {0} [built]
|
||||
cjs require ./mobile-stuff [0] ./example.js 2:1-26
|
||||
Child
|
||||
Hash: 78c68edab053f09ed9ab
|
||||
Version: webpack 1.3.0-beta6
|
||||
Time: 142ms
|
||||
Asset Size Chunks Chunk Names
|
||||
desktop.js 1673 0 [emitted] main
|
||||
chunk {0} desktop.js (main) 97 [rendered]
|
||||
> main [0] ./example.js
|
||||
[0] ./example.js 97 {0} [built]
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
Hash: da2299fe1ab7a2394372713bc011a9ed62a0ec77
|
||||
Version: webpack 1.3.0-beta6
|
||||
|
||||
WARNING in (undefined) mobile.js from UglifyJs
|
||||
Condition always true [./example.js:1,0]
|
||||
|
||||
WARNING in (undefined) desktop.js from UglifyJs
|
||||
Condition always false [./example.js:1,0]
|
||||
Dropping unreachable code [./example.js:2,0]
|
||||
Child
|
||||
Hash: da2299fe1ab7a2394372
|
||||
Version: webpack 1.3.0-beta6
|
||||
Time: 536ms
|
||||
Asset Size Chunks Chunk Names
|
||||
mobile.js 276 0 [emitted] main
|
||||
chunk {0} mobile.js (main) 117 [rendered]
|
||||
> main [0] ./example.js
|
||||
[0] ./example.js 97 {0} [built]
|
||||
[1] ./mobile-stuff.js 20 {0} [built]
|
||||
cjs require ./mobile-stuff [0] ./example.js 2:1-26
|
||||
|
||||
WARNING in mobile.js from UglifyJs
|
||||
Condition always true [./example.js:1,0]
|
||||
Child
|
||||
Hash: 713bc011a9ed62a0ec77
|
||||
Version: webpack 1.3.0-beta6
|
||||
Time: 498ms
|
||||
Asset Size Chunks Chunk Names
|
||||
desktop.js 254 0 [emitted] main
|
||||
chunk {0} desktop.js (main) 97 [rendered]
|
||||
> main [0] ./example.js
|
||||
[0] ./example.js 97 {0} [built]
|
||||
|
||||
WARNING in desktop.js from UglifyJs
|
||||
Condition always false [./example.js:1,0]
|
||||
Dropping unreachable code [./example.js:2,0]
|
||||
```
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
global.NO_TARGET_ARGS = true;
|
||||
require("../build-common");
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
if(ENV === "mobile") {
|
||||
require("./mobile-stuff");
|
||||
}
|
||||
console.log("Running " + ENV + " build");
|
||||
|
|
@ -0,0 +1 @@
|
|||
// mobile only stuff
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
# example.js
|
||||
|
||||
``` javascript
|
||||
{{example.js}}
|
||||
```
|
||||
|
||||
# webpack.config.js
|
||||
|
||||
``` javascript
|
||||
{{webpack.config.js}}
|
||||
```
|
||||
|
||||
# js/desktop.js
|
||||
|
||||
``` javascript
|
||||
{{js/desktop.js}}
|
||||
```
|
||||
|
||||
# js/mobile.js
|
||||
|
||||
``` javascript
|
||||
{{js/mobile.js}}
|
||||
```
|
||||
|
||||
# Info
|
||||
|
||||
## Uncompressed
|
||||
|
||||
```
|
||||
{{stdout}}
|
||||
```
|
||||
|
||||
## Minimized (uglify-js, no zip)
|
||||
|
||||
```
|
||||
{{min:stdout}}
|
||||
```
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
var path = require("path");
|
||||
var webpack = require("../../");
|
||||
module.exports = [
|
||||
{
|
||||
entry: "./example",
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "mobile.js"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
ENV: JSON.stringify("mobile")
|
||||
})
|
||||
]
|
||||
},
|
||||
{
|
||||
entry: "./example",
|
||||
output: {
|
||||
path: path.join(__dirname, "js"),
|
||||
filename: "desktop.js"
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
ENV: JSON.stringify("desktop")
|
||||
})
|
||||
]
|
||||
}
|
||||
];
|
||||
Loading…
Reference in New Issue