rollup / rollup

Next-generation ES module bundler
https://rollupjs.org
Other
25.24k stars 1.49k forks source link

How to export all members API from vue #5588

Open Minglu-Huo opened 1 month ago

Minglu-Huo commented 1 month ago

When I use Rollup to compile code for the production environment, I don't want Rollup to perform tree shaking on the Vue library, although tree shaking should be performed normally for other libraries. For example, within a component, even if I only import the ref API from Vue, I still want all members API of the Vue framework to be exported during compilation. Below are my Vue file and Vite configuration. Even when I configured global tree shaking to be false, the packaged Vue chunk still only exports the APIs related to ref. Moreover, I only want this to apply to Vue.

<template>
  <div>{{ time }}</div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import dayjs from 'dayjs';

  const time = ref(2024);

</script>

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [ vue()],
  build:{
    minify: false,
    rollupOptions:{
      treeshake: false,
      output: {
        minifyInternalExports: false,
        manualChunks:  {
            'vue': ['vue'],
        },
        chunkFileNames: (chunkInfo) =>{
          return '[name].chunk.js'
        }
      }
    }
  },
})
sunnylost commented 2 weeks ago

IIUC, you can use external: ['vue'] and manually copy Vue's dist file.