1.0.2 • Published 11 months ago

vite-raw-plugin v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Vite Raw Plugin

It's similar to raw-loader in Webpack。 Vite Raw Plugin will transfrom any type file to string.

Usage

import markdown file to string in Vue/React component and use markdown it transfrom

const { join } = require('path')
const vuePlugin = require('@vitejs/plugin-vue')
const markdownRawPlugin = require('vite-raw-plugin')

module.exports = {
  plugins: [
    vuePlugin(),
    markdownRawPlugin({
      fileRegex: /\.md$/
    })
  ],
  define: {
    __isBrowser__: true
  },
  resolve: {
    alias: {
      '@': join(process.cwd(), './web')
    },
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
  }
}

use in js file.

import content from 'xxx.md'

const md = require('markdown-it')
md.render(content)

TypeScript

To use with TypeScript, create a global.d.ts in your ./src/ directory

declare module '*.md' {
  const content: string
  export default content
}