text: const path = require('path')
  const webpack = require('webpack')
  const HtmlWebpackPlugin = require('html-webpack-plugin')
  const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin')
  
  const webpackConfig = (env) => ({
    entry: './src/index.tsx',
    ...(env.production || !env.development ? {} : { devtool: 'eval-source-map' }),
    resolve: {
      extensions: ['.ts', '.tsx', '.js'],
      //TODO waiting on https://github.com/dividab/tsconfig-paths-webpack-plugin/issues/61
      //@ts-ignore
      plugins: [new TsconfigPathsPlugin()],
      alias: {
        react: path.resolve(__dirname, './node_modules/react'),
        three: path.resolve(__dirname, './node_modules/three'),
        'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
        '@react-three/fiber': path.resolve(__dirname, './node_modules/@react-three/fiber'),
        '@react-three/drei': path.resolve(__dirname, './node_modules/@react-three/drei'),
        lamina: path.resolve(__dirname, '../src/index.tsx'),
      },
    },
    output: {
      path: path.join(__dirname, '/dist'),
      filename: 'build.js',
    },
    module: {
      rules: [
        {
          test: /\.tsx?$/,
          loader: 'ts-loader',
          options: {
            transpileOnly: true,
          },
          exclude: /dist/,
        },
        {
          test: /\.css$/i,
          use: ['style-loader', 'css-loader'],
        },
      ],
    },
    plugins: [
      new HtmlWebpackPlugin({
        template: './public/index.html',
      }),
      new webpack.DefinePlugin({
        'process.env.PRODUCTION': env.production || !env.development,
        'process.env.NAME': JSON.stringify(require('./package.json').name),
        'process.env.VERSION': JSON.stringify(require('./package.json').version),
      }),
    ],
  })
  
  module.exports = webpackConfig
  