wessberg / DI-compiler

A Custom Transformer for Typescript that enables compile-time Dependency Injection
MIT License
80 stars 7 forks source link

Usage with Vite.js #16

Open kien8995 opened 2 years ago

kien8995 commented 2 years ago

How i can use DI-compiler with Vite.js ?

arm1n commented 1 year ago

I've written a simple vite plugin applying the transformers:

const { di } = require('@wessberg/di-compiler');
const typescript = require('rollup-plugin-ts');

module.exports = function (options = {}) {
  return {
    name: 'vite:di',
    enforce: 'pre',
    ...typescript({
      ...options,
      transformers: [di],
      transpileOnly: true,
      exclude: ['**/*.test.ts'],
      tsconfig: (resolvedConfig) => ({ ...resolvedConfig, declaration: false }),
    }),
  };
};

Adjust options and config to your needs and you should be good to go.

i7N3 commented 1 year ago

If someone needs a full setup example, here it is.