UNPKG

1.71 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _path = require('path');
8
9var _fs = require('fs');
10
11var _rimraf = require('rimraf');
12
13var _rimraf2 = _interopRequireDefault(_rimraf);
14
15var _safe = require('colors/safe');
16
17var _safe2 = _interopRequireDefault(_safe);
18
19var _os = require('os');
20
21var _shellQuote = require('shell-quote');
22
23var _child_process = require('child_process');
24
25function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
27exports.default = function (_ref) {
28 var path = _ref.path;
29 var configPath = _ref.configPath;
30 var config = _ref.config;
31 var verbose = _ref.verbose;
32
33 var DEFAULT_OUTPUT_PATH = (0, _os.tmpdir)();
34
35 var webPackPath = require.resolve('webpack/bin/webpack');
36 var rnd = new Date().getTime() + '_' + Math.round(1000000 * Math.random());
37 var outPath = (0, _path.join)(config.output.path || DEFAULT_OUTPUT_PATH, '.webpack.res.' + rnd + '.js');
38
39 // I need to run webpack via execSync because I have not found the way how to run
40 // babel visitors asynchronously or run webpack compile synchronously
41 var webPackStdOut = (0, _child_process.execSync)((0, _shellQuote.quote)(['node', // for windows support
42 webPackPath, path, outPath, '--config', configPath, '--colors', '--bail']));
43
44 if (verbose) {
45 console.error( // eslint-disable-line
46 _safe2.default.blue('Webpack stdout for ' + path + '\n') + // eslint-disable-line prefer-template
47 _safe2.default.blue('---------\n') + (webPackStdOut + '\n') + _safe2.default.blue('---------'));
48 }
49
50 var webPackResult = (0, _fs.readFileSync)(outPath, { encoding: 'utf8' });
51 _rimraf2.default.sync(outPath);
52
53 return webPackResult;
54};
\No newline at end of file