Ask Your Question
3

Is it possible to set up Vite/Rollup to exclusively execute vue-tsc on entrypoints' included dependencies?

asked 2023-06-12 13:02:08 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-12 13:22:02 +0000

lalupa gravatar image

Yes, it is possible to set up Vite/Rollup to exclusively execute vue-tsc on entrypoints' included dependencies. This can be done by configuring the rollup-plugin-typescript2 plugin to use vue-tsc as the TypeScript compiler.

Here's an example Vite configuration:

// vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createVuePlugin } from 'vite-plugin-vue2'
import typescript from 'rollup-plugin-typescript2'

export default defineConfig({
  plugins: [
    vue(),
    createVuePlugin(),
    typescript({
      typescript: require('vue-tsc'),
      useTsconfigDeclarationDir: true,
      tsconfigOverride: {
        compilerOptions: {
          declaration: true,
          declarationDir: './dist/types',
        },
        include: ['path/to/entrypoints/**/*'], // Change this to match your entrypoints
        exclude: ['node_modules'],
      }
    })
  ]
})

Note the typescript options:

  • typescript: require('vue-tsc'): This sets the TypeScript compiler to vue-tsc.
  • useTsconfigDeclarationDir: true: This tells the TypeScript plugin to use the declarationDir specified in the tsconfigOverride.
  • tsconfigOverride: This sets options specific to the TypeScript configuration. In this case, we're setting the declaration option to true to generate TypeScript declaration files, and the declarationDir option to ./dist/types to output them into this directory. We're also setting the include option to only process files in path/to/entrypoints, and excluding node_modules.

With this configuration, Vite/Rollup will only execute vue-tsc on the included dependencies of the specified entrypoints.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-12 13:02:08 +0000

Seen: 12 times

Last updated: Jun 12 '23