text: const { join } = require('path');
  const webpack = require('webpack');
  const ExtractTextPlugin = require('extract-text-webpack-plugin');
  const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
  const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
  const chalk = require('chalk');
  
  const getBabelCommonConfig = require('./getBabelCommonConfig');
  const getTSCommonConfig = require('./getTSCommonConfig');
  
  /* eslint quotes:0 */
  
  module.exports = function getWebpackCommonConfig() {
    const jsFileName = '[name].js';
    const cssFileName = '[name].css';
    const commonName = 'common.js';
  
    const babelOptions = getBabelCommonConfig();
    const tsOptions = getTSCommonConfig();
  
    return {
      output: {
        filename: jsFileName,
        chunkFilename: jsFileName,
      },
  
      resolve: {
        modules: ['node_modules', join(__dirname, '../../node_modules')],
        extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.ts', '.tsx', '.js', '.jsx', '.json'],
      },
  
      resolveLoader: {
        modules: ['node_modules', join(__dirname, '../../node_modules')],
      },
  
      module: {
        noParse: [/moment.js/],
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            options: babelOptions,
          },
          {
            test: /\.jsx$/,
            loader: 'babel-loader',
            options: babelOptions,
          },
          {
            test: /\.tsx?$/,
            use: [{
              loader: 'babel-loader',
              options: babelOptions,
            }, {
              loader: 'ts-loader',
              options: {
                transpileOnly: true,
                compilerOptions: tsOptions,
              },
            }],
          },
          {
            test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url-loader?limit=10000&minetype=application/font-woff',
          },
          {
            test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url-loader?limit=10000&minetype=application/font-woff',
          },
          {
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url-loader?limit=10000&minetype=application/octet-stream',
          },
          {
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url-loader?limit=10000&minetype=application/vnd.ms-fontobject',
          },
          {
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url-loader?limit=10000&minetype=image/svg+xml',
          },
          {
            test: /\.(png|jpg|jpeg|gif)(\?v=\d+\.\d+\.\d+)?$/i,
            loader: 'url-loader?limit=10000',
          },
        ],
      },
  
      plugins: [
        new webpack.optimize.CommonsChunkPlugin({
          name: 'common',
          filename: commonName,
        }),
        new ExtractTextPlugin({
          filename: cssFileName,
          disable: false,
          allChunks: true,
        }),
        new CaseSensitivePathsPlugin(),
        new webpack.ProgressPlugin((percentage, msg, addInfo) => {
          const stream = process.stderr;
          if (stream.isTTY && percentage < 0.71) {
            stream.cursorTo(0);
            stream.write(`📦  ${chalk.magenta(msg)} (${chalk.magenta(addInfo)})`);
            stream.clearLine(1);
          } else if (percentage === 1) {
            console.log(chalk.green('\nwebpack: bundle build is now finished.'));
          }
        }),
        new FriendlyErrorsWebpackPlugin(),
      ],
    };
  }
  