UNPKG

1.66 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 _child_process = require('child_process');
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25exports.default = function (_ref) {
26 var path = _ref.path,
27 configPath = _ref.configPath,
28 config = _ref.config,
29 verbose = _ref.verbose;
30
31 var DEFAULT_OUTPUT_PATH = (0, _os.tmpdir)();
32
33 var webPackPath = require.resolve('webpack/bin/webpack');
34 var rnd = new Date().getTime() + '_' + Math.round(1000000 * Math.random());
35 var outPath = (0, _path.join)(config.output && config.output.path || DEFAULT_OUTPUT_PATH, '.webpack.res.' + rnd + '.js');
36
37 // I need to run webpack via execSync because I have not found the way how to run
38 // babel visitors asynchronously or run webpack compile synchronously
39 var webPackStdOut = (0, _child_process.execSync)(['node', // for windows support
40 webPackPath, path, outPath, '--config', configPath, '--bail'].join(' '));
41
42 if (verbose) {
43 console.error( // eslint-disable-line
44 _safe2.default.blue('Webpack stdout for ' + path + '\n') + // eslint-disable-line prefer-template
45 _safe2.default.blue('---------\n') + (webPackStdOut + '\n') + _safe2.default.blue('---------'));
46 }
47
48 var webPackResult = (0, _fs.readFileSync)(outPath, { encoding: 'utf8' });
49 _rimraf2.default.sync(outPath);
50
51 return webPackResult;
52};
\No newline at end of file