text: const webpack = require('webpack')
  const path = require('path')
  const CleanWebpackPlugin = require('clean-webpack-plugin')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  
  const WEBPACK_MODE_PRODUCTION = 'production'
  const OUTPUT_DIST_FOLDER = 'dist'
  const ENTRY_PATH = './src/cmp/infrastructure/build/cmp.js'
  const OUTPUT_FILENAME_DEV = 'cmp.dev.js'
  const OUTPUT_FILENAME_PRO = 'cmp.pro.js'
  
  const getMajorVersionFromPackageJsonVersion = () => {
    return parseInt(JSON.stringify(process.env.npm_package_version.split('.')[0]))
  }
  
  const webpackConfig = {
    devtool: 'inline-source-map',
    entry: ENTRY_PATH,
    output: {
      path: path.resolve(OUTPUT_DIST_FOLDER),
      filename: OUTPUT_FILENAME_DEV,
      libraryTarget: 'umd'
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /(node_modules|src\/cmp\/infrastructure\/build)/,
          use: {
            loader: 'babel-loader'
          }
        }
      ]
    },
    plugins: [
      new webpack.DefinePlugin({
        _CMP_VERSION: getMajorVersionFromPackageJsonVersion()
      }),
      new CleanWebpackPlugin([OUTPUT_DIST_FOLDER], {
        verbose: true,
        root: process.cwd()
      }),
      new HtmlWebpackPlugin({
        title: 'CMP Demo',
        template: 'resources/cmp/template.html',
        filename: 'index.html'
      })
    ]
  }
  
  module.exports = (env, argv) => {
    if (argv.mode === WEBPACK_MODE_PRODUCTION) {
      webpackConfig.output.filename = OUTPUT_FILENAME_PRO
      webpackConfig.devtool = false
    }
    return webpackConfig
  }
  