1 | exports["setup"] =
|
2 | (function(modules) {
|
3 |
|
4 | var installedModules = {};
|
5 |
|
6 |
|
7 | function __webpack_require__(moduleId) {
|
8 |
|
9 |
|
10 | if(installedModules[moduleId]) {
|
11 | return installedModules[moduleId].exports;
|
12 | }
|
13 |
|
14 | var module = installedModules[moduleId] = {
|
15 | i: moduleId,
|
16 | l: false,
|
17 | exports: {}
|
18 | };
|
19 |
|
20 |
|
21 | modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
22 |
|
23 |
|
24 | module.l = true;
|
25 |
|
26 |
|
27 | return module.exports;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 | __webpack_require__.m = modules;
|
33 |
|
34 |
|
35 | __webpack_require__.c = installedModules;
|
36 |
|
37 |
|
38 | __webpack_require__.i = function(value) { return value; };
|
39 |
|
40 |
|
41 | __webpack_require__.d = function(exports, name, getter) {
|
42 | if(!__webpack_require__.o(exports, name)) {
|
43 | Object.defineProperty(exports, name, {
|
44 | configurable: false,
|
45 | enumerable: true,
|
46 | get: getter
|
47 | /******/ });
|
48 | /******/ }
|
49 | /******/ };
|
50 | /******/
|
51 | /******/ // getDefaultExport function for compatibility with non-harmony modules
|
52 | /******/ __webpack_require__.n = function(module) {
|
53 | var getter = module && module.__esModule ?
|
54 | function getDefault() { return module['default']; } :
|
55 | function getModuleExports() { return module; };
|
56 | __webpack_require__.d(getter, 'a', getter);
|
57 | return getter;
|
58 | };
|
59 |
|
60 |
|
61 | __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
62 |
|
63 |
|
64 | __webpack_require__.p = "";
|
65 |
|
66 |
|
67 | return __webpack_require__(__webpack_require__.s = 4);
|
68 | })
|
69 |
|
70 | ([
|
71 |
|
72 | (function(module, exports) {
|
73 |
|
74 | module.exports = require("path");
|
75 |
|
76 | }),
|
77 |
|
78 | (function(module, exports) {
|
79 |
|
80 | module.exports = require("preconditions");
|
81 |
|
82 | }),
|
83 |
|
84 | (function(module, exports) {
|
85 |
|
86 | module.exports = require("webpack");
|
87 |
|
88 | }),
|
89 |
|
90 | (function(module, exports, __webpack_require__) {
|
91 |
|
92 | "use strict";
|
93 |
|
94 |
|
95 | Object.defineProperty(exports, "__esModule", {
|
96 | value: true
|
97 | });
|
98 |
|
99 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
100 |
|
101 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
102 |
|
103 | var _path = __webpack_require__(0);
|
104 |
|
105 | var _path2 = _interopRequireDefault(_path);
|
106 |
|
107 | var _preconditions = __webpack_require__(1);
|
108 |
|
109 | var _preconditions2 = _interopRequireDefault(_preconditions);
|
110 |
|
111 | var _webpack = __webpack_require__(2);
|
112 |
|
113 | var _webpack2 = _interopRequireDefault(_webpack);
|
114 |
|
115 | var _WebpackConfigurationFactory = __webpack_require__(5);
|
116 |
|
117 | var _WebpackConfigurationFactory2 = _interopRequireDefault(_WebpackConfigurationFactory);
|
118 |
|
119 | var _webpackDevServer = __webpack_require__(14);
|
120 |
|
121 | var _webpackDevServer2 = _interopRequireDefault(_webpackDevServer);
|
122 |
|
123 | var _url = __webpack_require__(13);
|
124 |
|
125 | var _url2 = _interopRequireDefault(_url);
|
126 |
|
127 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
128 |
|
129 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
130 |
|
131 | var UniversalWebApplicationSetup = function () {
|
132 | _createClass(UniversalWebApplicationSetup, null, [{
|
133 | key: 'create',
|
134 | value: function create(options) {
|
135 | return new UniversalWebApplicationSetup(options);
|
136 | }
|
137 | }]);
|
138 |
|
139 | function UniversalWebApplicationSetup(options) {
|
140 | _classCallCheck(this, UniversalWebApplicationSetup);
|
141 |
|
142 | var pc = _preconditions2.default.instance(options);
|
143 | pc.shouldBeDefined('name', 'Please provide the name of the application.');
|
144 | pc.shouldBeDefined('host', 'Please provide the host of the application.');
|
145 | pc.shouldBeDefined('port', 'Please provide the port of the application.');
|
146 | pc.shouldBeDefined('pingPort', 'Please provide the ping port of the application.');
|
147 | pc.shouldBeDefined('rootProjectPath', 'Please provide the rootProjectPath.');
|
148 | pc.shouldBeDefined('rootDeploymentPath', 'Please provide the rootDeploymentPath.');
|
149 | pc.shouldBeDefined('environment', 'Please provide the environment.');
|
150 |
|
151 | console.log('Application is initializing - ', options.name);
|
152 |
|
153 | this._options = options;
|
154 |
|
155 | if (this._options.modules == null || typeof this._options.modules === 'undefined') {
|
156 | this._options.modules = [];
|
157 | } else {
|
158 | if (!(this._options.modules instanceof Array)) {
|
159 | this._options.modules = [];
|
160 | console.warn('[COMPILER] Omitting modules entry. You should put the modules folder in an array.');
|
161 | }
|
162 | }
|
163 |
|
164 | this._applicationName = options.name;
|
165 | this._applicationHost = options.host;
|
166 |
|
167 | var rootProjectPath = options.rootProjectPath;
|
168 | var rootApplicationPath = _path2.default.join(options.rootProjectPath, 'applications', options.name);
|
169 |
|
170 | var rootDeploymentPath = options.rootDeploymentPath;
|
171 | var rootDeploymentApplicationPath = _path2.default.join(options.rootDeploymentPath, 'applications', options.name);
|
172 | var assetHost = options.assetHost !== null && typeof options.assetHost !== 'undefined' ? options.assetHost : options.host;
|
173 |
|
174 | var assetPath = options.assetPath || options.artifactPath || '/assets';
|
175 | assetPath += assetPath[assetPath.length - 1] !== '/' ? '/' : '';
|
176 |
|
177 | var artifactPath = options.artifactPath || options.assetPath || '/assets';
|
178 | artifactPath += artifactPath[artifactPath.length - 1] !== '/' ? '/' : '';
|
179 |
|
180 | console.log('==> rootProjectPath: ', rootProjectPath);
|
181 | console.log('==> rootApplicationPath: ', rootApplicationPath);
|
182 | console.log('==> rootDeploymentPath: ', rootDeploymentPath);
|
183 | console.log('==> rootDeploymentApplicationPath: ', rootDeploymentApplicationPath);
|
184 | console.log('==> supportedLocales: ', options.locales);
|
185 | console.log('==> modules: ', options.modules);
|
186 | console.log('==> logger (default - winston): ', options.loggerOptions ? options.loggerOptions.type : 'default');
|
187 |
|
188 | console.log('==> assetHost: ', assetHost);
|
189 | console.log('==> assetPath (default: /assets): ', assetPath);
|
190 | console.log('==> artifactPath (default: /assets): ', artifactPath);
|
191 | console.log('==> useBuildID (default: false): ', !!options.useBuildID);
|
192 |
|
193 | this._rootProjectPath = rootProjectPath;
|
194 | this._rootApplicationPath = rootApplicationPath;
|
195 | this._rootDeploymentPath = rootDeploymentPath;
|
196 | this._rootDeploymentApplicationPath = rootDeploymentApplicationPath;
|
197 |
|
198 | var projectConfigurationOptions = {
|
199 | applicationName: options.name,
|
200 | applicationHost: options.host,
|
201 |
|
202 | applicationAssetHost: assetHost,
|
203 | useBuildID: !!options.useBuildID,
|
204 | assetPath: assetPath,
|
205 | artifactPath: artifactPath,
|
206 |
|
207 | rootProjectPath: rootProjectPath,
|
208 | rootApplicationPath: rootApplicationPath,
|
209 | rootDeploymentPath: rootDeploymentPath,
|
210 | rootDeploymentApplicationPath: rootDeploymentApplicationPath,
|
211 | environment: options.environment,
|
212 | locales: options.locales,
|
213 | port: options.port,
|
214 | pingPort: options.pingPort,
|
215 | modules: options.modules,
|
216 | loggerOptions: options.loggerOptions
|
217 | };
|
218 |
|
219 | var webpackConfigurationOptions = _extends({
|
220 | devPort: options.devPort
|
221 | }, projectConfigurationOptions);
|
222 | console.log('Building webpack configurations, we will put on some commonly used plugin & configuration.');
|
223 | this._webpackConfigurationFactory = new _WebpackConfigurationFactory2.default(webpackConfigurationOptions);
|
224 | this._webpackConfiguration = this._webpackConfigurationFactory.createWebpackConfiguration(webpackConfigurationOptions);
|
225 | this._compiler = this._createWebpackCompiler(this._webpackConfiguration);
|
226 | }
|
227 |
|
228 | _createClass(UniversalWebApplicationSetup, [{
|
229 | key: 'run',
|
230 | value: function run() {
|
231 | var _this = this;
|
232 |
|
233 | if (this._options.environment === 'development') {
|
234 | console.log('[COMPILER] Initiating server compilation');
|
235 | var serverConfiguration = this._webpackConfiguration[0];
|
236 | var serverCompiler = this._createWebpackCompiler(serverConfiguration);
|
237 | serverCompiler.watch({
|
238 | aggregateTimeout: 300,
|
239 | poll: true
|
240 | }, function (err, stats) {
|
241 | if (err) console.error(err);
|
242 |
|
243 | console.log(stats.compilation.errors.toString({ colors: true }));
|
244 | console.log(stats.compilation.warnings.toString({ colors: true }));
|
245 | console.log('[COMPILER] Server compilation finished. Watching for server file changes.');
|
246 | });
|
247 |
|
248 | console.log('[COMPILER] Initiating client compilation using webpack-dev-server');
|
249 | var clientConfiguration = this._webpackConfiguration[1];
|
250 | var clientCompiler = this._createWebpackCompiler(clientConfiguration);
|
251 | var clientDevServer = new _webpackDevServer2.default(clientCompiler, {
|
252 | contentBase: _path2.default.join(this._rootApplicationPath, 'build'),
|
253 | hot: true,
|
254 | filename: 'main.js',
|
255 | proxy: {
|
256 | '**': 'http://localhost:' + this._options.port
|
257 | },
|
258 | watchOptions: {
|
259 | aggregateTimeout: 300,
|
260 | poll: 1000
|
261 | },
|
262 | stats: {
|
263 | color: true
|
264 | },
|
265 | publicPath: this._options.assetPath || '/assets',
|
266 | disableHostCheck: true
|
267 | });
|
268 | clientDevServer.listen(this._options.devPort, function (err) {
|
269 | if (err) {
|
270 | console.err('[ERROR]: ', err, err.stack);
|
271 | } else {
|
272 | console.log('\n[COMPILER] webpack-dev-server is listening at port ' + _this._options.devPort);
|
273 | console.log('[COMPILER] Client compilation finished. Watching for client file changes.');
|
274 | }
|
275 | });
|
276 | } else {
|
277 | console.log('[COMPILER] Initiating compilation.');
|
278 | this._compiler = this._createWebpackCompiler(this._webpackConfiguration);
|
279 | this._compiler.run(function (err, stats) {
|
280 | if (err) console.error(err);
|
281 | console.log(stats.toString({ colors: true }));
|
282 | console.log('[COMPILER] Compilation finished.');
|
283 | });
|
284 | }
|
285 | }
|
286 | }, {
|
287 | key: '_createWebpackCompiler',
|
288 | value: function _createWebpackCompiler(configuration) {
|
289 | var compiler = (0, _webpack2.default)(configuration);
|
290 | return compiler;
|
291 | }
|
292 | }]);
|
293 |
|
294 | return UniversalWebApplicationSetup;
|
295 | }();
|
296 |
|
297 | exports.default = UniversalWebApplicationSetup;
|
298 | module.exports = exports['default'];
|
299 |
|
300 | }),
|
301 |
|
302 | (function(module, exports, __webpack_require__) {
|
303 |
|
304 | "use strict";
|
305 |
|
306 |
|
307 | Object.defineProperty(exports, "__esModule", {
|
308 | value: true
|
309 | });
|
310 |
|
311 | var _UniversalWebApplicationSetup = __webpack_require__(3);
|
312 |
|
313 | var _UniversalWebApplicationSetup2 = _interopRequireDefault(_UniversalWebApplicationSetup);
|
314 |
|
315 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
316 |
|
317 | exports.default = {
|
318 | CatelaApplicationSetup: _UniversalWebApplicationSetup2.default
|
319 | };
|
320 | module.exports = exports['default'];
|
321 |
|
322 | }),
|
323 |
|
324 | (function(module, exports, __webpack_require__) {
|
325 |
|
326 | "use strict";
|
327 |
|
328 |
|
329 | Object.defineProperty(exports, "__esModule", {
|
330 | value: true
|
331 | });
|
332 |
|
333 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
334 |
|
335 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
336 |
|
337 |
|
338 |
|
339 | var _assetsWebpackPlugin = __webpack_require__(6);
|
340 |
|
341 | var _assetsWebpackPlugin2 = _interopRequireDefault(_assetsWebpackPlugin);
|
342 |
|
343 | var _chalk = __webpack_require__(7);
|
344 |
|
345 | var _chalk2 = _interopRequireDefault(_chalk);
|
346 |
|
347 | var _extractTextWebpackPlugin = __webpack_require__(9);
|
348 |
|
349 | var _extractTextWebpackPlugin2 = _interopRequireDefault(_extractTextWebpackPlugin);
|
350 |
|
351 | var _fs = __webpack_require__(10);
|
352 |
|
353 | var _fs2 = _interopRequireDefault(_fs);
|
354 |
|
355 | var _path = __webpack_require__(0);
|
356 |
|
357 | var _path2 = _interopRequireDefault(_path);
|
358 |
|
359 | var _preconditions = __webpack_require__(1);
|
360 |
|
361 | var _preconditions2 = _interopRequireDefault(_preconditions);
|
362 |
|
363 | var _progressBarWebpackPlugin = __webpack_require__(11);
|
364 |
|
365 | var _progressBarWebpackPlugin2 = _interopRequireDefault(_progressBarWebpackPlugin);
|
366 |
|
367 | var _statsWebpackPlugin = __webpack_require__(12);
|
368 |
|
369 | var _statsWebpackPlugin2 = _interopRequireDefault(_statsWebpackPlugin);
|
370 |
|
371 | var _webpack = __webpack_require__(2);
|
372 |
|
373 | var _webpack2 = _interopRequireDefault(_webpack);
|
374 |
|
375 | var _createFileWebpack = __webpack_require__(8);
|
376 |
|
377 | var _createFileWebpack2 = _interopRequireDefault(_createFileWebpack);
|
378 |
|
379 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
380 |
|
381 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
382 |
|
383 |
|
384 | var progressBarPlugin = new _progressBarWebpackPlugin2.default({
|
385 | format: ' build [:bar] ' + _chalk2.default.green.bold(':percent') + ' (:elapsed seconds)',
|
386 | clear: false
|
387 | });
|
388 |
|
389 | var WebpackConfigurationFactory = function () {
|
390 | function WebpackConfigurationFactory(options) {
|
391 | _classCallCheck(this, WebpackConfigurationFactory);
|
392 |
|
393 | var pc = _preconditions2.default.instance(options);
|
394 | pc.shouldBeDefined('applicationName', 'applicationName is required.');
|
395 | pc.shouldBeDefined('applicationHost', 'applicationHost is required.');
|
396 | pc.shouldBeDefined('applicationAssetHost', 'applicationAssetHost is required.');
|
397 | pc.shouldBeDefined('rootProjectPath', 'rootProjectPath is required.');
|
398 | pc.shouldBeDefined('rootApplicationPath', 'rootApplicationPath is required.');
|
399 | pc.shouldBeDefined('rootDeploymentPath', 'rootDeploymentPath is required.');
|
400 | pc.shouldBeDefined('rootDeploymentApplicationPath', 'rootDeploymentApplicationPath is required.');
|
401 | pc.shouldBeDefined('environment', 'environment is required.');
|
402 | pc.shouldBeDefined('locales', 'locales is required.');
|
403 | pc.shouldBeDefined('modules', 'modules is required');
|
404 |
|
405 | this._options = options;
|
406 | this._applicationHost = options.applicationHost;
|
407 | this._applicationName = options.applicationName;
|
408 | this._rootProjectPath = options.rootProjectPath;
|
409 | this._rootApplicationPath = options.rootApplicationPath;
|
410 | this._rootDeploymentPath = options.rootDeploymentPath;
|
411 | this._rootDeploymentApplicationPath = options.rootDeploymentApplicationPath;
|
412 | this._environment = options.environment;
|
413 |
|
414 |
|
415 | this._applicationAssetHost = options.applicationAssetHost;
|
416 | this._applicationAssetPath = options.assetPath;
|
417 | this._applicationArtifactPath = options.artifactPath;
|
418 | this._outputBuildPath = _path2.default.join(this._rootApplicationPath, 'build', this._environment);
|
419 | this._buildID = options.useBuildID ? JSON.stringify(Date.parse(new Date())) : '';
|
420 | this._publicPath = this._applicationAssetHost;
|
421 | this._artifactPath = this._applicationAssetHost + this._applicationArtifactPath + this._buildID;
|
422 | this._assetPath = this._applicationAssetHost + this._applicationAssetPath;
|
423 | this._serverOutputPath = _path2.default.join(this._outputBuildPath, 'server');
|
424 | this._clientOutputPath = _path2.default.join(this._outputBuildPath, 'client');
|
425 | }
|
426 |
|
427 | _createClass(WebpackConfigurationFactory, [{
|
428 | key: 'createWebpackConfiguration',
|
429 | value: function createWebpackConfiguration() {
|
430 | var client = this._createClientWebpackConfiguration();
|
431 | var server = this._createServerWebpackConfiguration();
|
432 | var config = [server, client];
|
433 | return config;
|
434 | }
|
435 | }, {
|
436 | key: '_createServerWebpackConfiguration',
|
437 | value: function _createServerWebpackConfiguration() {
|
438 | var options = this._options;
|
439 | var entry = this._buildServerEntry(options);
|
440 | var output = this._buildServerOutput(options);
|
441 | var plugins = this._buildServerPlugins(options);
|
442 | var common = this._buildCommon();
|
443 |
|
444 | var externalNodeModules = {};
|
445 | var nodeModulePath = _path2.default.join(this._rootProjectPath, 'node_modules');
|
446 | _fs2.default.readdirSync(nodeModulePath).filter(function (x) {
|
447 | return ['.bin'].indexOf(x) === -1;
|
448 | }).forEach(function (mod) {
|
449 | if (mod !== 'react-toolbox') {
|
450 | externalNodeModules[mod] = 'commonjs ' + mod;
|
451 | }
|
452 | });
|
453 |
|
454 | return _extends({
|
455 | name: 'server'
|
456 | }, common, {
|
457 | entry: entry,
|
458 | output: output,
|
459 | plugins: plugins,
|
460 | target: 'node',
|
461 | devtool: 'sourcemap',
|
462 | externals: externalNodeModules
|
463 | });
|
464 | }
|
465 | }, {
|
466 | key: '_createClientWebpackConfiguration',
|
467 | value: function _createClientWebpackConfiguration() {
|
468 | var options = this._options;
|
469 | var entry = this._buildClientEntry(options);
|
470 | var output = this._buildClientOutput(options);
|
471 | var plugins = this._buildClientPlugins(options);
|
472 | var common = this._buildCommon();
|
473 |
|
474 | return _extends({
|
475 | name: 'client'
|
476 | }, common, {
|
477 | entry: entry,
|
478 | output: output,
|
479 | plugins: plugins,
|
480 | devtool: 'sourcemap'
|
481 | });
|
482 | }
|
483 | }, {
|
484 | key: '_buildCommon',
|
485 | value: function _buildCommon() {
|
486 | var _this = this;
|
487 |
|
488 | var options = this._options;
|
489 | var loaders = this._buildLoaders(options);
|
490 | var applicationNamespace = _path2.default.join(this._rootProjectPath, 'applications', options.applicationName);
|
491 | var modulesDirectories = ['node_modules', applicationNamespace];
|
492 | this._options.modules.forEach(function (m) {
|
493 | var moduleNamespace = _path2.default.join(_this._rootProjectPath, m);
|
494 | modulesDirectories.push(moduleNamespace);
|
495 | });
|
496 | var config = {
|
497 | resolve: {
|
498 | modules: modulesDirectories,
|
499 | extensions: ['*', '.js', '.jsx', '.scss', '.css', '.ts', '.tsx']
|
500 | },
|
501 | module: _extends({}, loaders)
|
502 | };
|
503 | return config;
|
504 | }
|
505 | }, {
|
506 | key: '_buildServerEntry',
|
507 | value: function _buildServerEntry(options) {
|
508 | var entry = {
|
509 | server: _path2.default.join(this._rootApplicationPath, 'server.jsx')
|
510 | };
|
511 | return entry;
|
512 | }
|
513 | }, {
|
514 | key: '_buildClientEntry',
|
515 | value: function _buildClientEntry(options) {
|
516 | var environment = this._options.environment;
|
517 | var clientEntry = [];
|
518 | if (environment === 'development') {
|
519 | clientEntry.push('react-hot-loader/patch');
|
520 | clientEntry.push('webpack-dev-server/client?http://localhost:' + this._options.devPort + '/');
|
521 | }
|
522 | clientEntry.push(_path2.default.join(this._rootApplicationPath, 'client.jsx'));
|
523 | var entry = {
|
524 | libs: ['react', 'react-dom', 'react-router'],
|
525 | client: clientEntry
|
526 | };
|
527 | return entry;
|
528 | }
|
529 | }, {
|
530 | key: '_buildClientOutput',
|
531 | value: function _buildClientOutput(options) {
|
532 | |
533 |
|
534 |
|
535 |
|
536 |
|
537 | var filename = 'main.js';
|
538 | if (this._buildID) filename = this._buildID + '/main.js';
|
539 |
|
540 | var output = {
|
541 | path: this._clientOutputPath,
|
542 | publicPath: this._publicPath,
|
543 | filename: filename,
|
544 | chunkFilename: '[id].[name].js',
|
545 | sourceMapFilename: '[file].map'
|
546 | };
|
547 |
|
548 | return output;
|
549 | }
|
550 | }, {
|
551 | key: '_buildServerOutput',
|
552 | value: function _buildServerOutput(options) {
|
553 | |
554 |
|
555 |
|
556 |
|
557 |
|
558 | var output = {
|
559 | path: this._serverOutputPath,
|
560 | publicPath: this._publicPath,
|
561 | filename: 'main.js',
|
562 | chunkFilename: '[id].[name].js',
|
563 | sourceMapFilename: '__dev/assets/server/debugging/[file].map'
|
564 | };
|
565 |
|
566 | return output;
|
567 | }
|
568 | }, {
|
569 | key: '_buildLoaders',
|
570 | value: function _buildLoaders(options) {
|
571 | var loaders = {
|
572 | 'jsx': this._environment === 'development'
|
573 | ? ['react-hot-loader/webpack', 'babel-loader?compact=false'] : ['babel-loader?compact=false'],
|
574 | 'js': 'babel-loader?compact=false',
|
575 | 'tsx': 'ts-loader',
|
576 | 'ts': 'ts-loader',
|
577 | 'json': 'json-loader',
|
578 | 'json5': 'json5-loader',
|
579 | 'txt': 'raw-loader',
|
580 | 'png|jpg|jpeg|gif|svg': 'url-loader?limit=10000,fallback=file-loader,name=[name].[ext],publicPath=' + this._assetPath,
|
581 | 'otf|woff|woff2': 'url-loader?limit=100000,publicPath=' + this._assetPath,
|
582 | 'ttf|eot': 'file-loader?publicPath=' + this._assetPath,
|
583 | 'wav|mp3': 'file-loader?publicPath=' + this._assetPath,
|
584 | 'html': 'html-loader',
|
585 | 'md|markdown': ['html-loader', 'markdown-loader']
|
586 | };
|
587 |
|
588 | var cssLoader = 'css-loader?module&localIdentName=[name]-[local]-[hash:base64:5]';
|
589 |
|
590 | var stylesheetLoaders = {
|
591 | 'css': cssLoader,
|
592 | 'less': [cssLoader, 'less-loader'],
|
593 | 'styl': [cssLoader, 'stylus-loader'],
|
594 | 'scss|sass': [cssLoader, 'sass-loader']
|
595 | };
|
596 |
|
597 | Object.keys(stylesheetLoaders).forEach(function (ext) {
|
598 | var stylesheetLoader = stylesheetLoaders[ext];
|
599 | if (Array.isArray(stylesheetLoader)) {
|
600 | stylesheetLoader = stylesheetLoader.join('!');
|
601 | }
|
602 | stylesheetLoaders[ext] = _extractTextWebpackPlugin2.default.extract({
|
603 | fallback: 'style-loader',
|
604 | use: stylesheetLoader
|
605 | });
|
606 | });
|
607 |
|
608 | var resultLoaders = [].concat(this._loadersByExtension(loaders)).concat(this._loadersByExtension(stylesheetLoaders));
|
609 |
|
610 | return {
|
611 | loaders: resultLoaders
|
612 | };
|
613 | }
|
614 | }, {
|
615 | key: '_buildServerPlugins',
|
616 | value: function _buildServerPlugins(options) {
|
617 | var plugins = [];
|
618 |
|
619 |
|
620 | plugins.push(progressBarPlugin);
|
621 | plugins.push(new _statsWebpackPlugin2.default('stats.json', {
|
622 | chunkModules: true
|
623 | }));
|
624 | plugins.push(new _webpack2.default.DefinePlugin({
|
625 | '__PROJECT__': JSON.stringify(this._options),
|
626 | '__SERVER__': true,
|
627 | '__CLIENT__': false,
|
628 | '__BUILD_ID__': JSON.stringify(this._buildID),
|
629 | '__ARTIFACT_PATH__': JSON.stringify(this._artifactPath)
|
630 | }));
|
631 | plugins.push(new _extractTextWebpackPlugin2.default('styles.css'));
|
632 | plugins.push(new _assetsWebpackPlugin2.default({
|
633 | prettyPrint: true,
|
634 | publicPath: this._publicPath,
|
635 | path: this._serverOutputPath,
|
636 | update: true
|
637 | }));
|
638 | plugins.push(new _webpack2.default.WatchIgnorePlugin([/\.d\.ts$/]));
|
639 | return plugins;
|
640 | }
|
641 | }, {
|
642 | key: '_buildClientPlugins',
|
643 | value: function _buildClientPlugins(options) {
|
644 | var project = {
|
645 | applicationName: this._options.applicationName,
|
646 | applicationHost: this._options.applicationHost,
|
647 | environment: this._options.environment,
|
648 | locales: this._options.locales
|
649 | };
|
650 | var plugins = [];
|
651 |
|
652 | plugins.push(progressBarPlugin);
|
653 |
|
654 | if (this._options.environment === 'development') {
|
655 | plugins.push(new _webpack2.default.PrefetchPlugin('react'));
|
656 | plugins.push(new _webpack2.default.PrefetchPlugin('react-router'));
|
657 | plugins.push(new _webpack2.default.PrefetchPlugin('react-dom/lib/ReactComponentBrowserEnvironment'));
|
658 | plugins.push(new _webpack2.default.HotModuleReplacementPlugin());
|
659 | }
|
660 |
|
661 | plugins.push(new _statsWebpackPlugin2.default('stats.json', {
|
662 | chunkModules: true
|
663 | }));
|
664 |
|
665 | var filename = 'commons.js';
|
666 | if (this._buildID) filename = this._buildID + '/commons.js';
|
667 |
|
668 | plugins.push(new _webpack2.default.optimize.CommonsChunkPlugin({
|
669 | name: 'libs',
|
670 | filename: filename,
|
671 | minChunks: 0
|
672 | }));
|
673 |
|
674 | if (this._options.environment !== 'development') {
|
675 | plugins.push(new _webpack2.default.optimize.UglifyJsPlugin({ compressor: { warnings: false } }));
|
676 | plugins.push(new _webpack2.default.ExtendedAPIPlugin());
|
677 | }
|
678 |
|
679 | plugins.push(new _webpack2.default.DefinePlugin({
|
680 | 'process.env': {
|
681 | 'NODE_ENV': JSON.stringify(this._environment)
|
682 | },
|
683 | '__SERVER__': false,
|
684 | '__CLIENT__': true,
|
685 | '__PROJECT__': JSON.stringify(project),
|
686 | '__BUILD_ID__': JSON.stringify(this._buildID),
|
687 | '__ARTIFACT_PATH__': JSON.stringify(this._artifactPath)
|
688 | }));
|
689 | plugins.push(new _webpack2.default.NoEmitOnErrorsPlugin());
|
690 |
|
691 | var styleName = 'styles.css';
|
692 | if (this._buildID) styleName = this._buildID + '/styles.css';
|
693 |
|
694 | plugins.push(new _extractTextWebpackPlugin2.default(styleName));
|
695 | plugins.push(new _assetsWebpackPlugin2.default({
|
696 | prettyPrint: true,
|
697 | publicPath: this._publicPath,
|
698 | path: this._clientOutputPath,
|
699 | update: true
|
700 | }));
|
701 | plugins.push(new _webpack2.default.WatchIgnorePlugin([/\.d\.ts$/]));
|
702 |
|
703 | if (this._buildID) {
|
704 | plugins.push(new _createFileWebpack2.default({
|
705 | path: this._outputBuildPath,
|
706 | fileName: 'BUILD_ID',
|
707 | content: this._buildID
|
708 | }));
|
709 | }
|
710 | return plugins;
|
711 | }
|
712 | }, {
|
713 | key: '_extsToRegExp',
|
714 | value: function _extsToRegExp(exts) {
|
715 | return new RegExp('\\.(' + exts.map(function (ext) {
|
716 | return ext.replace(/\./g, '\\.');
|
717 | }).join('|') + ')(\\?.*)?$');
|
718 | }
|
719 | }, {
|
720 | key: '_loadersByExtension',
|
721 | value: function _loadersByExtension(obj) {
|
722 | var self = this;
|
723 | var loaders = [];
|
724 | Object.keys(obj).forEach(function (key) {
|
725 | var exts = key.split('|');
|
726 | var value = obj[key];
|
727 | var entry;
|
728 | if (exts.indexOf('js') >= 0) {
|
729 | entry = {
|
730 | exclude: [/node_modules/],
|
731 | options: {
|
732 | ignore: [/node_modules/]
|
733 | },
|
734 | test: self._extsToRegExp(exts)
|
735 | };
|
736 | } else {
|
737 | entry = {
|
738 | test: self._extsToRegExp(exts)
|
739 | };
|
740 | }
|
741 |
|
742 | if (Array.isArray(value)) {
|
743 | entry.loaders = value;
|
744 | } else if (typeof value === 'string') {
|
745 | entry.loader = value;
|
746 | } else {
|
747 | Object.keys(value).forEach(function (valueKey) {
|
748 | entry[valueKey] = value[valueKey];
|
749 | });
|
750 | }
|
751 | loaders.push(entry);
|
752 | });
|
753 | return loaders;
|
754 | }
|
755 | }]);
|
756 |
|
757 | return WebpackConfigurationFactory;
|
758 | }();
|
759 |
|
760 | exports.default = WebpackConfigurationFactory;
|
761 | module.exports = exports['default'];
|
762 |
|
763 | }),
|
764 |
|
765 | (function(module, exports) {
|
766 |
|
767 | module.exports = require("assets-webpack-plugin");
|
768 |
|
769 | }),
|
770 |
|
771 | (function(module, exports) {
|
772 |
|
773 | module.exports = require("chalk");
|
774 |
|
775 | }),
|
776 |
|
777 | (function(module, exports) {
|
778 |
|
779 | module.exports = require("create-file-webpack");
|
780 |
|
781 | }),
|
782 |
|
783 | (function(module, exports) {
|
784 |
|
785 | module.exports = require("extract-text-webpack-plugin");
|
786 |
|
787 | }),
|
788 |
|
789 | (function(module, exports) {
|
790 |
|
791 | module.exports = require("fs");
|
792 |
|
793 | }),
|
794 |
|
795 | (function(module, exports) {
|
796 |
|
797 | module.exports = require("progress-bar-webpack-plugin");
|
798 |
|
799 | }),
|
800 |
|
801 | (function(module, exports) {
|
802 |
|
803 | module.exports = require("stats-webpack-plugin");
|
804 |
|
805 | }),
|
806 |
|
807 | (function(module, exports) {
|
808 |
|
809 | module.exports = require("url");
|
810 |
|
811 | }),
|
812 |
|
813 | (function(module, exports) {
|
814 |
|
815 | module.exports = require("webpack-dev-server");
|
816 |
|
817 | })
|
818 | ]);
|
819 |
|
\ | No newline at end of file |