"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.configWebpackDevMiddleware = configWebpackDevMiddleware;
exports.webpackDevMiddlewareConfig = webpackDevMiddlewareConfig;

var _webpack = require("webpack");

var _webpackDevMiddleware = _interopRequireDefault(require("webpack-dev-middleware"));

var _webpackConfig = _interopRequireDefault(require("../bundler/webpack/webpackConfig"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function webpackDevMiddlewareConfig(options) {
  const {
    publicPath
  } = options;
  return {
    stats: 'minimal',
    index: 'index.html',
    publicPath,
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  };
}

function configWebpackDevMiddleware(app, options) {
  const config = (0, _webpackConfig.default)(options);
  const compiler = (0, _webpack.webpack)(config); // console.log("mode", mode)

  const devMiddleware = (0, _webpackDevMiddleware.default)(compiler, webpackDevMiddlewareConfig(options));
  app.use(devMiddleware);
  return {
    compiler
  };
}