Source:  Twitter logo

I've a demo react app setup on replit.

I simply used replit's default react template as it is and added the annotated section to the vite.config.js file:

import reactRefresh from '@vitejs/plugin-react-refresh'

 * @type { import('vite').UserConfig }
export default {
  plugins: [reactRefresh()],
  server: {
    host: '',
    hmr: {
      port: 443,
  ////////////// <- added this section
  build: {
    rollupOptions: {
      external: [ 'react', 'react-dom'],
      output: {
        globals: {
          'react': 'React',
          'react-dom': 'ReactDOM'
  ////////////// <- upto here

and the external react scripts to the index.html file:

<script src="" crossorigin></script>
<script src="" crossorigin></script>

The purpose is to declare the react and react-dom modules as external so that vite doesn't include them in the bundle.

But for some reason (not clear from vite or rollup's documentation), the bundling is not doing as intended.

Any help is appreciated.

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).