Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Rollup Plugin Vue', () => {

expect(code).toEqual(
expect.stringContaining(
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
)
)
expect(code).toEqual(expect.stringContaining(`script.render = render`))
Expand All @@ -66,7 +66,7 @@ describe('Rollup Plugin Vue', () => {
)
expect(code).toEqual(
expect.stringContaining(
`import { render } from "example.vue?vue&type=template&id=063a7d4c"`
`import { render } from "example.vue?vue&type=template&id=063a7d4c&lang.js"`
)
)
expect(code).toEqual(expect.stringContaining(`script.render = render`))
Expand Down
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
const descriptor = getDescriptor(query.filename)
const hasScoped = descriptor.styles.some((s) => s.scoped)
if (query.src) {
this.addWatchFile(query.filename);
this.addWatchFile(query.filename)
}

if (query.type === 'template') {
debug(`transform(${id})`)
const block = descriptor.template!
Expand Down Expand Up @@ -478,7 +478,7 @@ function getTemplateCode(
const idQuery = `&id=${id}`
const scopedQuery = hasScoped ? `&scoped=true` : ``
const srcQuery = descriptor.template.src ? `&src` : ``
const attrsQuery = attrsToQuery(descriptor.template.attrs)
const attrsQuery = attrsToQuery(descriptor.template.attrs, 'js', true)
const query = `?vue&type=template${idQuery}${srcQuery}${scopedQuery}${attrsQuery}`
templateRequest = _(src + query)
templateImport = `import { ${renderFnName} } from ${templateRequest}`
Expand Down Expand Up @@ -638,12 +638,15 @@ function _(any: any) {
return JSON.stringify(any)
}

function normalizeSourceMap(map: SFCTemplateCompileResults['map'], id: string): any {
function normalizeSourceMap(
map: SFCTemplateCompileResults['map'],
id: string
): any {
if (!map) return null as any

if (!id.includes('type=script')) {
map.file = id;
map.sources[0] = id;
map.file = id
map.sources[0] = id
}

return {
Expand Down