{"size": 4563, "ext": "js", "max_stars_repo_path": "webpack.config.dist.js", "max_stars_repo_name": "whernebrink/enterprise-wc", "max_stars_repo_stars_event_min_datetime": "2020-10-13T19:00:22.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-30T04:12:07.000Z", "max_issues_repo_path": "webpack.config.dist.js", "max_issues_repo_name": "whernebrink/enterprise-wc", "max_issues_repo_issues_event_min_datetime": "2020-07-22T17:43:46.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T19:58:19.000Z", "max_forks_repo_path": "webpack.config.dist.js", "max_forks_repo_name": "whernebrink/enterprise-wc", "max_forks_repo_forks_event_min_datetime": "2021-03-04T01:44:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-18T08:08:21.000Z"}
{"max_stars_count": 13, "max_issues_count": 487, "max_forks_count": 7, "avg_line_length": 30.2185430464, "max_line_length": 118, "alphanum_fraction": 0.5150120535}
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const sass = require('sass');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const path = require('path');
const glob = require('glob');

const isProduction = process.argv[process.argv.indexOf('--mode') + 1] === 'production';

module.exports = {
  entry: glob.sync('./src/**/**/ids*.js',).reduce((acc, filePath) => {
    acc[filePath.replace('./src', '').replace('.js', '')] = filePath;
    return acc;
  }, {}),
  devtool: isProduction ? 'cheap-module-source-map' : 'source-map', // try source-map for prod
  mode: isProduction ? 'production' : 'development',
  performance: {
    hints: false
  },
  cache: {
    type: 'filesystem',
    version: '0.0.0'
  },
  optimization: {
    minimize: !!isProduction,
    minimizer: [
      new TerserPlugin({
        test: /\.js(\?.*)?$/i
      }),
    ]
  },
  output: {
    library: '[name]-lib.js',
    libraryTarget: 'umd',
    libraryExport: 'default',
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: [
          {
            // Options are all in babel.config.js
            loader: 'babel-loader',
          }
        ]
      },
      {
        test: /\.scss$/,
        exclude: [
          /node_modules/,
          path.resolve(__dirname, 'demos')
        ],
        use: [
          'sass-to-string',
          {
            loader: 'sass-loader',
            options: {
              sassOptions: {
                outputStyle: 'compressed',
              },
            },
          },
        ],
      },
      {
        test: /\.scss$/,
        exclude: [
          /node_modules/,
          path.resolve(__dirname, 'src')
        ],
        use: [
          // Creates `style` nodes from JS strings
          {
            loader: 'style-loader'
          },
          // Translates CSS into CommonJS
          'css-loader',
          // Compiles Sass to CSS
          'sass-loader',
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new MiniCssExtractPlugin({
      filename: 'css/[name].min.css'
    }),
    new BundleAnalyzerPlugin({
      analyzerMode: 'static',
      reportFilename: `./build-report/index-${isProduction ? 'prod' : 'dev'}.html`
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: './src/components/**/*.scss',
          to({ absoluteFilename }) {
            const baseName = path.basename(absoluteFilename);
            const folders = path.dirname(absoluteFilename).split(path.sep);
            return `${folders[folders.length - 2]}/${folders[folders.length - 1]}/${baseName.replace('scss', 'css')}`;
          },
          transform(content, transFormPath) {
            const result = sass.renderSync({
              file: transFormPath
            });
            let css = result.css.toString();
            css = css.replace(':host {', ':root {');
            return css;
          }
        },
        {
          from: './src/**/**/index.js',
          to({ absoluteFilename }) {
            const baseName = path.basename(absoluteFilename);
            const folders = path.dirname(absoluteFilename).split(path.sep);
            let filePath = `${folders[folders.length - 2]}/${folders[folders.length - 1]}/${baseName}`;
            filePath = filePath.replace('src/', '');
            return filePath;
          }
        },
        {
          from: './src/**/**/*.d.ts',
          to({ absoluteFilename }) {
            const baseName = path.basename(absoluteFilename);
            const folders = path.dirname(absoluteFilename).split(path.sep);
            let filePath = `${folders[folders.length - 2]}/${folders[folders.length - 1]}/${baseName}`;
            filePath = filePath.replace('src/', '');
            return filePath;
          }
        },
        {
          from: './src/**/**/*.md',
          to({ absoluteFilename }) {
            const baseName = path.basename(absoluteFilename);
            const folders = path.dirname(absoluteFilename).split(path.sep);
            let filePath = `${folders[folders.length - 2]}/${folders[folders.length - 1]}/${baseName}`;
            filePath = filePath.replace('src/', '');
            return filePath;
          }
        }
      ]
    })
  ]
};
