Skip to content

Commit ce3a2cb

Browse files
committed
added multi compiler example
1 parent b0caa69 commit ce3a2cb

6 files changed

Lines changed: 316 additions & 0 deletions

File tree

examples/multi-compiler/README.md

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
2+
# example.js
3+
4+
``` javascript
5+
if(ENV === "mobile") {
6+
require("./mobile-stuff");
7+
}
8+
console.log("Running " + ENV + " build");
9+
```
10+
11+
# webpack.config.js
12+
13+
``` javascript
14+
var path = require("path");
15+
var webpack = require("../../");
16+
module.exports = [
17+
{
18+
entry: "./example",
19+
output: {
20+
path: path.join(__dirname, "js"),
21+
filename: "mobile.js"
22+
},
23+
plugins: [
24+
new webpack.DefinePlugin({
25+
ENV: JSON.stringify("mobile")
26+
})
27+
]
28+
},
29+
{
30+
entry: "./example",
31+
output: {
32+
path: path.join(__dirname, "js"),
33+
filename: "desktop.js"
34+
},
35+
plugins: [
36+
new webpack.DefinePlugin({
37+
ENV: JSON.stringify("desktop")
38+
})
39+
]
40+
}
41+
];
42+
```
43+
44+
# js/desktop.js
45+
46+
``` javascript
47+
/******/ (function(modules) { // webpackBootstrap
48+
/******/ // The module cache
49+
/******/ var installedModules = {};
50+
/******/
51+
/******/ // The require function
52+
/******/ function __webpack_require__(moduleId) {
53+
/******/
54+
/******/ // Check if module is in cache
55+
/******/ if(installedModules[moduleId])
56+
/******/ return installedModules[moduleId].exports;
57+
/******/
58+
/******/ // Create a new module (and put it into the cache)
59+
/******/ var module = installedModules[moduleId] = {
60+
/******/ exports: {},
61+
/******/ id: moduleId,
62+
/******/ loaded: false
63+
/******/ };
64+
/******/
65+
/******/ // Execute the module function
66+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
67+
/******/
68+
/******/ // Flag the module as loaded
69+
/******/ module.loaded = true;
70+
/******/
71+
/******/ // Return the exports of the module
72+
/******/ return module.exports;
73+
/******/ }
74+
/******/
75+
/******/
76+
/******/ // expose the modules object (__webpack_modules__)
77+
/******/ __webpack_require__.m = modules;
78+
/******/
79+
/******/ // expose the module cache
80+
/******/ __webpack_require__.c = installedModules;
81+
/******/
82+
/******/ // __webpack_public_path__
83+
/******/ __webpack_require__.p = "js/";
84+
/******/
85+
/******/ // Load entry module and return exports
86+
/******/ return __webpack_require__(0);
87+
/******/ })
88+
/************************************************************************/
89+
/******/ ([
90+
/* 0 */
91+
/*!********************!*\
92+
!*** ./example.js ***!
93+
\********************/
94+
/***/ function(module, exports, __webpack_require__) {
95+
96+
if(false) {
97+
require("./mobile-stuff");
98+
}
99+
console.log("Running " + ("desktop") + " build");
100+
101+
/***/ }
102+
/******/ ])
103+
```
104+
105+
# js/mobile.js
106+
107+
``` javascript
108+
/******/ (function(modules) { // webpackBootstrap
109+
/******/ // The module cache
110+
/******/ var installedModules = {};
111+
/******/
112+
/******/ // The require function
113+
/******/ function __webpack_require__(moduleId) {
114+
/******/
115+
/******/ // Check if module is in cache
116+
/******/ if(installedModules[moduleId])
117+
/******/ return installedModules[moduleId].exports;
118+
/******/
119+
/******/ // Create a new module (and put it into the cache)
120+
/******/ var module = installedModules[moduleId] = {
121+
/******/ exports: {},
122+
/******/ id: moduleId,
123+
/******/ loaded: false
124+
/******/ };
125+
/******/
126+
/******/ // Execute the module function
127+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
128+
/******/
129+
/******/ // Flag the module as loaded
130+
/******/ module.loaded = true;
131+
/******/
132+
/******/ // Return the exports of the module
133+
/******/ return module.exports;
134+
/******/ }
135+
/******/
136+
/******/
137+
/******/ // expose the modules object (__webpack_modules__)
138+
/******/ __webpack_require__.m = modules;
139+
/******/
140+
/******/ // expose the module cache
141+
/******/ __webpack_require__.c = installedModules;
142+
/******/
143+
/******/ // __webpack_public_path__
144+
/******/ __webpack_require__.p = "js/";
145+
/******/
146+
/******/ // Load entry module and return exports
147+
/******/ return __webpack_require__(0);
148+
/******/ })
149+
/************************************************************************/
150+
/******/ ([
151+
/* 0 */
152+
/*!********************!*\
153+
!*** ./example.js ***!
154+
\********************/
155+
/***/ function(module, exports, __webpack_require__) {
156+
157+
if(true) {
158+
__webpack_require__(/*! ./mobile-stuff */ 1);
159+
}
160+
console.log("Running " + ("mobile") + " build");
161+
162+
/***/ },
163+
/* 1 */
164+
/*!*************************!*\
165+
!*** ./mobile-stuff.js ***!
166+
\*************************/
167+
/***/ function(module, exports, __webpack_require__) {
168+
169+
// mobile only stuff
170+
171+
/***/ }
172+
/******/ ])
173+
```
174+
175+
# Info
176+
177+
## Uncompressed
178+
179+
```
180+
Hash: d6e452828343eb86930778c68edab053f09ed9ab
181+
Version: webpack 1.3.0-beta6
182+
Child
183+
Hash: d6e452828343eb869307
184+
Version: webpack 1.3.0-beta6
185+
Time: 173ms
186+
Asset Size Chunks Chunk Names
187+
mobile.js 1878 0 [emitted] main
188+
chunk {0} mobile.js (main) 117 [rendered]
189+
> main [0] ./example.js
190+
[0] ./example.js 97 {0} [built]
191+
[1] ./mobile-stuff.js 20 {0} [built]
192+
cjs require ./mobile-stuff [0] ./example.js 2:1-26
193+
Child
194+
Hash: 78c68edab053f09ed9ab
195+
Version: webpack 1.3.0-beta6
196+
Time: 142ms
197+
Asset Size Chunks Chunk Names
198+
desktop.js 1673 0 [emitted] main
199+
chunk {0} desktop.js (main) 97 [rendered]
200+
> main [0] ./example.js
201+
[0] ./example.js 97 {0} [built]
202+
```
203+
204+
## Minimized (uglify-js, no zip)
205+
206+
```
207+
Hash: da2299fe1ab7a2394372713bc011a9ed62a0ec77
208+
Version: webpack 1.3.0-beta6
209+
210+
WARNING in (undefined) mobile.js from UglifyJs
211+
Condition always true [./example.js:1,0]
212+
213+
WARNING in (undefined) desktop.js from UglifyJs
214+
Condition always false [./example.js:1,0]
215+
Dropping unreachable code [./example.js:2,0]
216+
Child
217+
Hash: da2299fe1ab7a2394372
218+
Version: webpack 1.3.0-beta6
219+
Time: 536ms
220+
Asset Size Chunks Chunk Names
221+
mobile.js 276 0 [emitted] main
222+
chunk {0} mobile.js (main) 117 [rendered]
223+
> main [0] ./example.js
224+
[0] ./example.js 97 {0} [built]
225+
[1] ./mobile-stuff.js 20 {0} [built]
226+
cjs require ./mobile-stuff [0] ./example.js 2:1-26
227+
228+
WARNING in mobile.js from UglifyJs
229+
Condition always true [./example.js:1,0]
230+
Child
231+
Hash: 713bc011a9ed62a0ec77
232+
Version: webpack 1.3.0-beta6
233+
Time: 498ms
234+
Asset Size Chunks Chunk Names
235+
desktop.js 254 0 [emitted] main
236+
chunk {0} desktop.js (main) 97 [rendered]
237+
> main [0] ./example.js
238+
[0] ./example.js 97 {0} [built]
239+
240+
WARNING in desktop.js from UglifyJs
241+
Condition always false [./example.js:1,0]
242+
Dropping unreachable code [./example.js:2,0]
243+
```

examples/multi-compiler/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.NO_TARGET_ARGS = true;
2+
require("../build-common");

examples/multi-compiler/example.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if(ENV === "mobile") {
2+
require("./mobile-stuff");
3+
}
4+
console.log("Running " + ENV + " build");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// mobile only stuff
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
# example.js
3+
4+
``` javascript
5+
{{example.js}}
6+
```
7+
8+
# webpack.config.js
9+
10+
``` javascript
11+
{{webpack.config.js}}
12+
```
13+
14+
# js/desktop.js
15+
16+
``` javascript
17+
{{js/desktop.js}}
18+
```
19+
20+
# js/mobile.js
21+
22+
``` javascript
23+
{{js/mobile.js}}
24+
```
25+
26+
# Info
27+
28+
## Uncompressed
29+
30+
```
31+
{{stdout}}
32+
```
33+
34+
## Minimized (uglify-js, no zip)
35+
36+
```
37+
{{min:stdout}}
38+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var path = require("path");
2+
var webpack = require("../../");
3+
module.exports = [
4+
{
5+
entry: "./example",
6+
output: {
7+
path: path.join(__dirname, "js"),
8+
filename: "mobile.js"
9+
},
10+
plugins: [
11+
new webpack.DefinePlugin({
12+
ENV: JSON.stringify("mobile")
13+
})
14+
]
15+
},
16+
{
17+
entry: "./example",
18+
output: {
19+
path: path.join(__dirname, "js"),
20+
filename: "desktop.js"
21+
},
22+
plugins: [
23+
new webpack.DefinePlugin({
24+
ENV: JSON.stringify("desktop")
25+
})
26+
]
27+
}
28+
];

0 commit comments

Comments
 (0)