Skip to content
Snippets Groups Projects
Select Git revision
  • 8ab2eb3222cb87e0a0f35b3476863b6e53acd6b1
  • 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
  • webpack.config.js 2.30 KiB
    const path = require('path');
    const TerserPlugin = require('terser-webpack-plugin');
    const paths = require('./config/paths');
    
    const eslintLoaderConfig = {
      test: /\.(js|mjs|jsx)$/,
      enforce: 'pre',
      use: [
        {
          options: {
            formatter: require.resolve('react-dev-utils/eslintFormatter'),
            eslintPath: require.resolve('eslint'),
    
          },
          loader: require.resolve('eslint-loader'),
        },
      ],
      include: paths.appSrc,
    };
    
    const babelLoaderConfig = {
      test: /\.(js|mjs|jsx)$/,
      include: paths.appSrc, // CRL
      loader: require.resolve('babel-loader'),
      options: {
        plugins: [
          [
            require.resolve('babel-plugin-named-asset-import'),
            {
              loaderMap: {
                svg: {
                  ReactComponent: '@svgr/webpack?-prettier,-svgo![path]',
                },
              },
            },
          ],
        ],
        cacheDirectory: true,
        // Save disk space when time isn't as important
        cacheCompression: true,
        compact: true,
      },
    };
    
    const baseConfig = [
      {
        entry: './src/store.js',
        output: {
          path: path.join(__dirname, 'dist'),
          filename: 'm3core.umd.js',
          libraryTarget: 'umd',
          library: 'm3core',
        },
        module: {
          rules: [
            eslintLoaderConfig,
            babelLoaderConfig,
          ],
        },
      },
      {
        entry: './src/index.js',
        output: {
          path: path.join(__dirname, 'dist'),
          filename: 'mirador.min.js',
          libraryTarget: 'umd',
          library: 'Mirador',
          libraryExport: 'default',
        },
        resolve: { extensions: ['.js'] },
        module: {
          rules: [
            eslintLoaderConfig,
            babelLoaderConfig,
            {
              test: /\.scss$/,
              use: [
                'style-loader', // creates style nodes from JS strings
                'css-loader', // translates CSS into CommonJS
                'sass-loader', // compiles Sass to CSS, using Node Sass by default
              ],
            }],
        },
        optimization: {
          minimizer: [
            new TerserPlugin({
              terserOptions: {
                mangle: false,
              },
            }),
          ],
        },
      },
    ];
    
    module.exports = (env, options) => {
      const isProduction = options.mode === 'production';
      return baseConfig.map((config) => {
        config.devtool = !isProduction ? 'eval-source-map' : false; // eslint-disable-line no-param-reassign
        return config;
      });
    };