Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--watch mode does full re-build instead of incremental build #16048

Closed
7 tasks done
Ruthvik94 opened this issue Feb 28, 2024 · 3 comments
Closed
7 tasks done

--watch mode does full re-build instead of incremental build #16048

Ruthvik94 opened this issue Feb 28, 2024 · 3 comments

Comments

@Ruthvik94
Copy link

Ruthvik94 commented Feb 28, 2024

Describe the bug

My Vite config:

/** @type {import('vite').UserConfig} */
import path from 'path';
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import react from '@vitejs/plugin-react';
import { rm } from 'fs/promises';
import { visualizer } from 'rollup-plugin-visualizer';

const BUILD_DIR = path.resolve(
  __dirname,
  './web/webroot/_ui/responsive/common/'
);

export default defineConfig({
  plugins: [
    react(),
    splitVendorChunkPlugin(),
    visualizer({
      gzipSize: true,
      open: false,
    }),
  ],
  mode: 'development',
  esbuild: {
    loader: 'jsx',
  },
  optimizeDeps: {
    esbuildOptions: {
      loader: {
        '.js': 'jsx',
      },
    },
    exclude: ['*.locale', '*moment'],
  },
  resolve: {
    alias: {
      base: path.resolve(
        __dirname,
        './web/webroot/WEB-INF/_ui-src/react/assets/stylesheets/base'
      ),
      components: path.resolve(
        __dirname,
        './web/webroot/WEB-INF/_ui-src/react/assets/stylesheets/components'
      ),
      '@images': path.resolve(BUILD_DIR, './images'),
      '@fonts': path.resolve(BUILD_DIR, './fonts'),
      public: path.resolve(__dirname, 'public/'),
    },
  },
  base: './',
  logLevel: 'info',
  build: {
    outDir: path.resolve(__dirname, './web/webroot/_ui/responsive/common'),
    emptyOutDir: false,
    assetsDir: 'assets',
    rollupOptions: {
      input: {
        index: './src/App.jsx',
        customTable: './src/CustomTable/CustomTable.jsx',
        wizard: './src/Wizard/Wizard.jsx',
      },
      output: {
        entryFileNames: `js/react/[name].bundle.js`,
        chunkFileNames: function ({ name }) {
          if (name === 'vendor') {
            return `js/react/vendors.bundle.js`;
          }

          return `js/react/[name].bundle.js`;
        },
        assetFileNames: function (file) {
          if (file.name.match(/\.(bmp|gif|jpe?g|svg|png)$/)) {
            return `images/[name].[hash:8].[ext]`;
          }

          if (file.name.match(/\.(ttf|otf|eot|woff|woff2)$/)) {
            return `fonts/[name].[ext]`;
          }

          if (file.name.match(/\.(le|c)ss$/)) {
            return `css/[name].css`;
          }
        },
      },
    },
    watch: true,
    minify: false,
    sourcemap: true,
  },
});

webpack config: similar to above vite config with minor changes to be compatible with webpack v5

export default = {
  devtool: 'source-map',
  watch: true,
  watchOptions: {
    ignored: ['node_modules'],
    poll: 1000
  }
};

Issue is, Webpack v5 does a build, emits files and watches for changes. On any change, the rebuild happens almost instantaneously.
Whereas in Vite, build happens successfully and watches for changes. On change, it's a full rebuild taking more time than initial first build rather than doing incremental build.

Reproduction

https://stackblitz.com/edit/vitejs-vite-1ytjiw

Steps to reproduce

Intially run command "npm run vite:watch", time it takes to build is around ~10s. Modify a file and check the build time, it's around ~4s.

Now run command, "npm run dev:webpack", intial build roughly takes the same amount of time. Modify a file and check the build time, it's less than ~1s around 600ms.

System Info

'''shell
Windows, mac
'''

Used Package Manager

npm

Logs

No response

Validations

Copy link

Hello @Ruthvik94. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs reproduction will be closed if they have no activity within 3 days.

Copy link

stackblitz bot commented Mar 1, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@Ruthvik94 Ruthvik94 changed the title --watch mode does full re-build instead of incremental build **--watch** mode does full re-build instead of incremental build Mar 1, 2024
@Ruthvik94 Ruthvik94 changed the title **--watch** mode does full re-build instead of incremental build <code>--watch</code> mode does full re-build instead of incremental build Mar 1, 2024
@Ruthvik94 Ruthvik94 changed the title <code>--watch</code> mode does full re-build instead of incremental build --watch mode does full re-build instead of incremental build Mar 1, 2024
@Ruthvik94
Copy link
Author

I've updated the reproduction URL, can someone check this?

@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants