Skip to content

Commit 650a5ab

Browse files
committed
fix: generate empty sourcemap to bypass warning
close #6
1 parent 3d26228 commit 650a5ab

File tree

6 files changed

+28
-18
lines changed

6 files changed

+28
-18
lines changed

example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
},
1212
"devDependencies": {
1313
"@vitejs/plugin-vue": "^3.0.1",
14-
"@vue/compiler-sfc": "^3.2.37",
1514
"cross-env": "^7.0.3",
1615
"markdown-it-prism": "^2.2.4",
1716
"prismjs": "^1.28.0",

example/vite.config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { UserConfig } from 'vite'
1+
import { defineConfig } from 'vite'
22
import Vue from '@vitejs/plugin-vue'
33
import Markdown from 'vite-plugin-vue-markdown'
44
import prism from 'markdown-it-prism'
55
import Pages from 'vite-plugin-pages'
66
import Inspect from 'vite-plugin-inspect'
77

8-
const config: UserConfig = {
8+
export default defineConfig({
99
plugins: [
1010
Vue({
1111
include: [/\.vue$/, /\.md$/],
@@ -22,6 +22,7 @@ const config: UserConfig = {
2222
}),
2323
Inspect(),
2424
],
25-
}
26-
27-
export default config
25+
build: {
26+
sourcemap: true,
27+
},
28+
})

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,14 @@
5757
"@antfu/ni": "^0.17.2",
5858
"@types/node": "^18.6.1",
5959
"@vue/test-utils": "^2.0.2",
60+
"@vueuse/head": "^0.7.7",
6061
"bumpp": "^8.2.1",
6162
"eslint": "^8.20.0",
6263
"rollup": "^2.77.0",
6364
"tsup": "^6.2.0",
6465
"typescript": "^4.7.4",
6566
"vite": "^3.0.3",
66-
"vitest": "^0.19.1"
67+
"vitest": "^0.19.1",
68+
"vue": "^3.2.37"
6769
}
6870
}

pnpm-lock.yaml

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function VitePluginMarkdown(userOptions: Options = {}): Plugin {
3232

3333
const defaultRead = ctx.read
3434
ctx.read = async function () {
35-
return markdownToVue(ctx.file, await defaultRead())
35+
return markdownToVue(ctx.file, await defaultRead()).code
3636
}
3737
},
3838
}

src/markdown.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import MarkdownIt from 'markdown-it'
22
import { toArray, uniq } from '@antfu/utils'
33
import { componentPlugin } from '@mdit-vue/plugin-component'
44
import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter'
5+
import type { TransformResult } from 'vite'
56
import type { MarkdownEnv, ResolvedOptions } from './types'
67

78
const scriptSetupRE = /<\s*script([^>]*)\bsetup\b([^>]*)>([\s\S]*)<\/script>/mg
@@ -69,7 +70,7 @@ export function createMarkdown(options: ResolvedOptions) {
6970

7071
options.markdownItSetup(markdown)
7172

72-
return (id: string, raw: string) => {
73+
return (id: string, raw: string): TransformResult => {
7374
const { wrapperClasses, wrapperComponent, transforms, headEnabled, frontmatterPreprocess } = options
7475

7576
raw = raw.trimStart()
@@ -174,10 +175,15 @@ export function createMarkdown(options: ResolvedOptions) {
174175
: []),
175176
]
176177

177-
return [
178+
const code = [
178179
`<template>${html}</template>`,
179180
...scripts.map(i => i.trim()).filter(Boolean),
180181
...customBlocks.blocks,
181182
].join('\n')
183+
184+
return {
185+
code,
186+
map: { mappings: '' } as any,
187+
}
182188
}
183189
}

0 commit comments

Comments
 (0)