Using vite components in a react + webpack app slows the build process

For a little bit of context, we’re performing a migration that involves creating a UI component library which is a monorepo that includes a number of vite projects. Each vite project corresponds to a specific component (for instance, a Button component, a Modal, etc.).

This library was done in the past with a different structure and using webpack, so no functional changes are applied, just migration from webpack -> vite.

Each component has the following vite.config.js

import { defineConfig } from 'vite'
import path from 'path'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [
    react(),
  ],
  build: {
    lib: {
      entry: path.resolve(__dirname, 'src/main.jsx'),
      name: 'my-component'
    },
    rollupOptions: {
      external: ['react', 'react-dom'],
      output: {
        exports: "named",
        globals: {
          'react': 'React',
          'react-dom': 'ReactDOM'
        }
      }
    },
  },
})

So when running:

- yarn build
- npm version patch --workspace=my-component
- npm publish --workspace=my-component

My component is built and stored in a dist folder, which is published into our repository.

Now I’m trying to use those components from another app that we have built with React and webpack (not gonna be migrated to vite).

The issue that we’re encountering is that it gets stuck at 87% sealing code generation when adding the vite components.

Is there a specific configuration needed for webpack to build vite projects?

My webpack config:

const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const webpack = require('webpack')
const AddPropsPlugin = require('./add-props-plugin')
const AddDepsToHost = require('@remote-comp/add-deps-to-host-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const Dotenv = require('dotenv-webpack')
const path = require('path')
const CDN_PATH =
  process.env.CDN_PATH ||
  'some-url'

module.exports = function (_env, argv) {
  const production = ...
  const development = !production
  const analyze = Boolean(argv.analyze)
  process.env.NODE_ENV = process.env.NODE_ENV || production
    ? 'production' : 'development' 
  return {
    devtool: development && 'cheap-module-source-map',
    entry: './my-entry-file.js',
    externals: {
      react: 'react',
      'react-redux': 'react-redux',
      'react-router': 'react-router',
      'react-router-dom': 'react-router-dom',
    },
    output: {
      libraryTarget: 'commonjs',
      path: path.resolve(__dirname, 'my-path'),
      filename: 'js/[name].[contenthash:8].js',
      publicPath: CDN_PATH,
    },
    module: {
      rules: [
        {
          test: /.js(x)?$/,
          exclude: /node_modules/,
          use: {
            loader: 'babel-loader',
            options: {
              cacheDirectory: true,
              cacheCompression: true,
              envName: production ? 'production' : 'development',
            },
          },
        },
        {
          test: /.s[ac]ss$/i,
          use: ['style-loader', 'css-loader', 'sass-loader'],
        },
        {
          test: /.svg/,
          use: [
            {
              loader: 'svg-url-loader',
              options: {
                limit: 10000,
                name: 'media/[name].[contenthash:8].[ext]',
              },
            },
          ],
        },
        {
          test: /.(png|jpg|gif)$/i,
          use: {
            loader: 'url-loader',
            options: {
              limit: 8192,
              name: 'media/[name].[contenthash:8].[ext]',
            },
          },
        },
        {
          test: /.(eot|otf|ttf|woff|woff2)$/,
          loader: require.resolve('file-loader'),
          options: {
            name: 'media/[name].[contenthash:8].[ext]',
          },
        },
        {
          test: /(gitInfo.txt)$/,
          loader: require.resolve('url-loader'),
          options: {
            name: 'assets/[name].[contenthash:8].[ext]',
          },
        },
      ],
    },
    resolve: {
      modules: [path.resolve(__dirname, './src'), 'node_modules'],
      extensions: ['.js', '.jsx', '.json'],
      fallback: {
        "path": require.resolve("path-browserify")
      }
    },
    plugins: [
      new webpack.ProgressPlugin((percentage, message, ...args) => {
        console.log((percentage * 100).toFixed(2) + '%', message, ...args);
      }),
      new Dotenv(),
      new webpack.optimize.LimitChunkCountPlugin({
        maxChunks: 1
      }),
      new webpack.ProgressPlugin(),
      new AddPropsPlugin(),
      new CleanWebpackPlugin(),
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(
          production ? 'production' : 'development',
        ),
        'process.env.CDN_PATH': JSON.stringify(CDN_PATH),
      }),
      new AddDepsToHost({
        name: 'my-host',
      }),
      analyze ? new BundleAnalyzerPlugin() : null,
    ].filter(Boolean),
    optimization: {
      minimize: production,
      moduleIds: 'named',
      minimizer: [
        new TerserWebpackPlugin({
          terserOptions: {
            sourceMap: true,
            compress: {
              comparisons: false,
            },
            mangle: {
              safari10: true,
            },
            output: {
              comments: false,
              ascii_only: true,
            },
            warnings: false,
          },
        }),
        new OptimizeCssAssetsPlugin(),
      ],
    },
  }
}

I’ve tried debugging with this plugin (wasn’t there before)

      new webpack.ProgressPlugin((percentage, message, ...args) => {
        console.log((percentage * 100).toFixed(2) + '%', message, ...args);
      }),

But just stalls at 87%:

86% sealing record chunks86.67% sealing record chunks RecordIdsPlugin
86% sealing record chunks RecordIdsPlugin86.67% sealing record chunks
86% sealing record chunks87.31% sealing module hashing
87% sealing module hashing87.31% sealing module hashing
87% sealing module hashing87.95% sealing code generation
87% sealing code generation87.95% sealing code generation
87% sealing code generation

Also added in externals

'react-dom': 'react-dom',

to match the vite.config.js but that didn’t work either.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật