hmsk / vite-plugin-markdown

A vite plugin to import a Markdown file in various formats like Front Matter, HTML, ToC, and React/Vue Component
https://www.npmjs.com/package/vite-plugin-markdown
MIT License
259 stars 44 forks source link

add missing docs for typescript ESM #480

Closed dimaslanjaka closed 7 months ago

dimaslanjaka commented 7 months ago

here my working config vite.config.ts

import react from '@vitejs/plugin-react';
import dotenv from 'dotenv';
import { createRequire } from 'node:module';
import path from 'upath';
import { UserConfig, defineConfig } from 'vite';
import * as mdp from 'vite-plugin-markdown';

const { plugin: mdPlugin, Mode } = mdp;
dotenv.config({ override: true });

const require = createRequire(import.meta.url);

const config: UserConfig = {
  plugins: [react(), mdPlugin({ mode: [Mode.HTML, Mode.MARKDOWN, Mode.TOC, Mode.REACT] })],
  server: {
    port: 4000
  },
  resolve: {
    alias: {
      '*': path.resolve('.'),
      '@utils': path.resolve('./src/utils'),
      '@components': path.resolve('./src/components'),
      '@routes': path.resolve('./src/routes'),
      '@assets': path.resolve('./src/assets'),
      '@src': path.resolve('./src'),
      '@root': path.resolve('./'),
      '@post': path.resolve('./src/posts'),
      'react/jsx-dev-runtime': require.resolve('react/jsx-dev-runtime'),
      'react/jsx-runtime': require.resolve('react/jsx-runtime')
    }
  }
};

export default defineConfig(config);

package.json

{ "type": "module" }
hmsk commented 7 months ago

ESM will be supported officially from v3 which is still in pre-release state https://github.com/hmsk/vite-plugin-markdown/releases/tag/v3.0.0-0