Skip to content
Snippets Groups Projects
Select Git revision
  • 73bff104c91b1171fb78247fa0e33c7bbe874650
  • annotation-on-video default protected
  • demo_ci
  • 3-upstream-01022023
  • master
  • gh3538-captions
  • 16-adapt-for-images-annot
  • 15-api-for-annotations-on-video
  • 15-annotations-on-videos
  • video_for_annotations
  • wip-1-annotations-on-videos
  • 9-videoviewer-tests
  • 9_wip_videotests
  • 6-fix-tests-and-ci
  • _fix_ci
  • wip-webpack-from-git
16 results

webpack.config.js

Blame
  • user avatar
    Chris Beer authored
    8c4f6ead
    History
    webpack.config.js 2.13 KiB
    const path = require('path');
    const fs = require('fs');
    const webpack = require('webpack');
    const TerserPlugin = require('terser-webpack-plugin');
    const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
    
    /** */
    const baseConfig = mode => ({
      entry: ['./src/polyfills.js', './src/index.js'],
      module: {
        rules: [
          {
            include: path.resolve(fs.realpathSync(process.cwd()), '.'), // CRL
            loader: require.resolve('babel-loader'),
            options: {
              // Save disk space when time isn't as important
              cacheCompression: true,
              cacheDirectory: true,
              compact: true,
              envName: mode,
            },
            test: /\.(js|mjs|jsx)$/,
          },
        ],
      },
      optimization: {
        minimizer: [
          new TerserPlugin({
            extractComments: true,
          }),
        ],
      },
      output: {
        filename: 'mirador.min.js',
        hashFunction: 'md5',
        library: 'Mirador',
        libraryExport: 'default',
        libraryTarget: 'umd',
        path: path.join(__dirname, 'dist'),
        publicPath: '/dist/',
      },
      plugins: [
        new webpack.IgnorePlugin({
          resourceRegExp: /@blueprintjs\/(core|icons)/, // ignore optional UI framework dependencies
        }),
      ],
      resolve: {
        alias: {
          // needs shared global state for context to work
          'react-dnd': path.resolve(path.join(__dirname, 'node_modules', 'react-dnd')),
        },
        extensions: ['.js'],
      },
    });
    
    module.exports = (env, options) => {
      const isProduction = options.mode === 'production';
      const config = baseConfig(options.mode);
    
      if (isProduction) {
        return {
          ...config,
          devtool: 'source-map',
          mode: 'production',
          plugins: [
            ...(config.plugins || []),
            new webpack.optimize.LimitChunkCountPlugin({
              maxChunks: 1,
            }),
          ],
        };
      }
    
      return {
        ...config,
        devServer: {
          hot: true,
          port: 4444,
          static: [
            './__tests__/integration/mirador',
            './__tests__/fixtures',
          ],
        },
        devtool: 'eval-source-map',
        mode: 'development',
        plugins: [
          ...(config.plugins || []),
          new ReactRefreshWebpackPlugin(),
        ],
      };
    };