Socket
Socket
Sign inDemoInstall

vite-plugin-generate-exports

Package Overview
Dependencies
205
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vite-plugin-generate-exports

Generate Exports at Build Time


Version published
Maintainers
1
Install size
8.13 MB
Created

Readme

Source

vite-plugin-generate-exports

⚠️ This plugin is experimental and is subject to change. It is not currently recommended that you use this plugin.

Install

# Install Plugin
npm i -D vite-plugin-generate-exports

# Required if you want type generation
npm i -D rollup-plugin-typescript2
// vite.config.ts

import GenerateExports from 'vite-plugin-generate-exports'
import { defineConfig } from 'vite'

export default defineConfig({
  lib: {
    // Build Config
  },
  plugins: [
    GenerateExports({
      patterns: [
        {
          matchTokens: ['// Start_Exports', '// End_Exports'],
          files: 'src/components/**/*.vue'
        }
      ]
    })
  ],
})

Generating Types

If you want type generation you currently have to switch to using rollup-plugin-typescript2.

// vite.config.ts

import GenerateExports from 'vite-plugin-generate-exports'
import ts from 'rollup-plugin-typescript2'
import { defineConfig } from 'vite'

export default defineConfig({
  esbuild: false,
  build: {
    // Build Config
  }
  build: {

  }
  plugins: [
    GenerateExports({
      patterns: [
        {
          matchTokens: ['// Start_Exports', '// End_Exports'],
          files: 'src/components/**/*.vue'
        }
      ]
    }),
    {
      apply: 'build',
      ...ts({
        tsconfig: './tsconfig.json',
        check: false,
        useTsconfigDeclarationDir: true,
      }),
    },
  ],
})

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "module": "ESNext",
    "target": "es2016",
    "lib": ["DOM", "ESNext"],
    "strict": true,
    "esModuleInterop": true,
    "incremental": true,
    "skipLibCheck": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "declaration": true,
    "declarationDir": "./dist",
    "outDir": "./dist",
    "paths": {
      "~/*": ["src/*"]
    }
  },
  "include": ["src"],
  "exclude": [
    "node_modules",
    "**/**/*.test.ts",
    "**/**/*.md",
    "**/dist",
    "packages/.test",
    "packages/_docs"
  ]
}

Usage

At build time your files will be injected as exports between the two match tokens you set in the config.

// main.ts

export const install = () => {
  // This is my install function
}

// Start_Exports

// End_Exports

License

MIT License © 2021-PRESENT Jacob Clevenger

FAQs

Last updated on 01 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc