How to exclude a vue folder from being build in vite?

Member

by ryleigh , in category: Javascript , 4 months ago

How to exclude a vue folder from being build in vite?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 4 months ago

@ryleigh 

To exclude a specific folder from being built in Vite, you can use the exclude option in your Vite configuration file (vite.config.js). Below is an example of how you can exclude a vue folder from being built in Vite:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
// vite.config.js

import { defineConfig } from 'vite';

export default defineConfig({
  build: {
    // Exclude the 'vue' folder from being built
    rollupOptions: {
      input: {
        main: 'src/main.js'
      },
      output: {
        entryFileNames: '[name].js',
        chunkFileNames: 'chunks/[name]-[hash].js',
        manualChunks: undefined,
        preserveModules: false
      },
      exclude: ['vue'] // Add the folder name to be excluded
    }
  }
});


In this configuration, the exclude option under rollupOptions instructs Vite to exclude the specified folder (vue in this case) from the build process. This folder will not be bundled into the final output.


After making this change in your Vite configuration file, rebuild your project to see the exclusion take effect.