Package Exports
- vite-raw-plugin
- vite-raw-plugin/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vite-raw-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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
}