"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = createWebpackConfig;
function _webpack() {
  const data = require("webpack");
  _webpack = function () {
    return data;
  };
  return data;
}
function _terserWebpackPlugin() {
  const data = _interopRequireDefault(require("terser-webpack-plugin"));
  _terserWebpackPlugin = function () {
    return data;
  };
  return data;
}
function _cssMinimizerWebpackPlugin() {
  const data = _interopRequireDefault(require("css-minimizer-webpack-plugin"));
  _cssMinimizerWebpackPlugin = function () {
    return data;
  };
  return data;
}
function _path() {
  const data = _interopRequireDefault(require("path"));
  _path = function () {
    return data;
  };
  return data;
}
function _htmlWebpackPlugin() {
  const data = _interopRequireDefault(require("html-webpack-plugin"));
  _htmlWebpackPlugin = function () {
    return data;
  };
  return data;
}
function _webpackMerge() {
  const data = require("webpack-merge");
  _webpackMerge = function () {
    return data;
  };
  return data;
}
function _webpack2() {
  const data = require("@teambit/webpack");
  _webpack2 = function () {
    return data;
  };
  return data;
}
function _html() {
  const data = require("./html");
  _html = function () {
    return data;
  };
  return data;
}
function _webpackBase() {
  const data = _interopRequireDefault(require("./webpack.base.config"));
  _webpackBase = function () {
    return data;
  };
  return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function createWebpackConfig(outputDir, entryFiles, title, publicDir) {
  const baseConfig = (0, _webpackBase().default)(outputDir, entryFiles);
  const browserConfig = createBrowserConfig(outputDir, title, publicDir);
  const combined = (0, _webpackMerge().merge)(baseConfig, browserConfig);
  return combined;
}
function createBrowserConfig(outputDir, title, publicDir) {
  const browserConfig = {
    // target: 'web', // already default

    output: {
      path: _path().default.resolve(outputDir, publicDir),
      // webpack uses `publicPath` to determine where the app is being served from.
      // It requires a trailing slash, or the file assets will get an incorrect path.
      // We inferred the "public path" (such as / or /my-project) from homepage.
      publicPath: '/'
    },
    optimization: {
      minimize: true,
      minimizer: [
      // This is only used in production mode
      new (_terserWebpackPlugin().default)({
        terserOptions: {
          // this ensures the Class Names for all Schema Classes is not minimized
          // so that schemaObjToClass can match the correct Class Name during runtime
          keep_classnames: new RegExp('.*(Schema)$'),
          parse: {
            // We want terser to parse ecma 8 code. However, we don't want it
            // to apply any minification steps that turns valid ecma 5 code
            // into invalid ecma 5 code. This is why the 'compress' and 'output'
            // sections only apply transformations that are ecma 5 safe
            // https://github.com/facebook/create-react-app/pull/4234
            ecma: 8
          },
          compress: {
            ecma: 5,
            warnings: false,
            // Disabled because of an issue with Uglify breaking seemingly valid code:
            // https://github.com/facebook/create-react-app/issues/2376
            // Pending further investigation:
            // https://github.com/mishoo/UglifyJS2/issues/2011
            comparisons: false,
            // Disabled because of an issue with Terser breaking valid code:
            // https://github.com/facebook/create-react-app/issues/5250
            // Pending further investigation:
            // https://github.com/terser-js/terser/issues/120
            inline: 2
          },
          mangle: {
            safari10: true
          },
          output: {
            ecma: 5,
            comments: false,
            // Turned on because emoji and regex is not minified properly using default
            // https://github.com/facebook/create-react-app/issues/2488
            ascii_only: true
          }
        }
      }), new (_cssMinimizerWebpackPlugin().default)({
        minimizerOptions: {
          preset: ['default', {
            minifyFontValues: {
              removeQuotes: false
            }
          }]
        }
      })],
      // Automatically split vendor and commons
      // https://twitter.com/wSokra/status/969633336732905474
      // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
      splitChunks: {
        chunks: 'all',
        name: false
      },
      // Keep the runtime chunk separated to enable long term caching
      // https://twitter.com/wSokra/status/969679223278505985
      // https://github.com/facebook/create-react-app/issues/5358
      runtimeChunk: {
        name: entrypoint => `runtime-${entrypoint.name}`
      }
    },
    plugins: [new (_htmlWebpackPlugin().default)({
      inject: true,
      templateContent: (0, _html().html)(title),
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeEmptyAttributes: true,
        removeStyleLinkTypeAttributes: true,
        keepClosingSlash: true,
        minifyJS: true,
        minifyCSS: true,
        minifyURLs: true
      }
    }), new (_webpack().ProvidePlugin)({
      process: _webpack2().fallbacksProvidePluginConfig.process
    })]
  };
  return browserConfig;
}

//# sourceMappingURL=webpack.browser.config.js.map