{"size": 1517, "ext": "js", "max_stars_repo_path": "protocol-designer/webpack.config.js", "max_stars_repo_name": "ethguo/opentrons", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "protocol-designer/webpack.config.js", "max_issues_repo_name": "ethguo/opentrons", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "protocol-designer/webpack.config.js", "max_forks_repo_name": "ethguo/opentrons", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.5, "max_line_length": 88, "alphanum_fraction": 0.6677653263}
'use strict'

const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

const {rules} = require('@opentrons/webpack-config')
const {gitDescribeSync} = require('git-describe')

const DEV = process.env.NODE_ENV !== 'production'
const PROTOCOL_DESIGNER_ENV_VAR_PREFIX = 'OT_PD_'

const gitInfo = gitDescribeSync()
const OT_PD_VERSION = gitInfo && gitInfo.raw

const passThruEnvVars = Object.keys(process.env)
  .filter(v => v.startsWith(PROTOCOL_DESIGNER_ENV_VAR_PREFIX))
  .concat(['NODE_ENV'])

const envVarsWithDefaults = {OT_PD_VERSION}

const envVars = passThruEnvVars.reduce((acc, envVar) =>
  ({[envVar]: '', ...acc}),
  {...envVarsWithDefaults}
)

console.log('PD version: ' + (process.env.OT_PD_VERSION || OT_PD_VERSION || 'UNKNOWN!'))

module.exports = {
  entry: [
    './src/index.js'
  ],

  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist')
  },

  module: {
    rules: [
      rules.js,
      rules.localCss,
      rules.images
    ]
  },

  devServer: {
    historyApiFallback: true
  },

  devtool: DEV ? 'eval-source-map' : 'source-map',

  plugins: [
    new webpack.EnvironmentPlugin(envVars),

    new ExtractTextPlugin({
      filename: 'bundle.css',
      disable: DEV,
      ignoreOrder: true
    })
  ]
}

if (DEV) {
  module.exports.entry.unshift(
    'react-hot-loader/patch'
  )

  module.exports.plugins.push(
    new webpack.NoEmitOnErrorsPlugin(),
    new webpack.NamedModulesPlugin()
  )
}
