1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  */
    
  8. 
    
  9. 'use strict';
    
  10. 
    
  11. const path = require('path');
    
  12. const rimraf = require('rimraf');
    
  13. const webpack = require('webpack');
    
  14. 
    
  15. const isProduction = process.env.NODE_ENV === 'production';
    
  16. rimraf.sync(path.resolve(__dirname, '../build'));
    
  17. webpack(
    
  18.   {
    
  19.     mode: isProduction ? 'production' : 'development',
    
  20.     devtool: isProduction ? 'source-map' : 'cheap-module-source-map',
    
  21.     entry: [path.resolve(__dirname, '../src/index.js')],
    
  22.     output: {
    
  23.       path: path.resolve(__dirname, '../build'),
    
  24.       filename: 'main.js',
    
  25.     },
    
  26.     module: {
    
  27.       rules: [
    
  28.         {
    
  29.           test: /\.js$/,
    
  30.           use: 'babel-loader',
    
  31.           exclude: /node_modules/,
    
  32.         },
    
  33.       ],
    
  34.     },
    
  35.   },
    
  36.   (err, stats) => {
    
  37.     if (err) {
    
  38.       console.error(err.stack || err);
    
  39.       if (err.details) {
    
  40.         console.error(err.details);
    
  41.       }
    
  42.       process.exit(1);
    
  43.     }
    
  44.     const info = stats.toJson();
    
  45.     if (stats.hasErrors()) {
    
  46.       console.log('Finished running webpack with errors.');
    
  47.       info.errors.forEach(e => console.error(e));
    
  48.       process.exit(1);
    
  49.     } else {
    
  50.       console.log('Finished running webpack.');
    
  51.     }
    
  52.   }
    
  53. );