Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for new script setup and css var injection
- Loading branch information
Showing
9 changed files
with
215 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as fs from 'fs' | ||
import { SFCDescriptor } from '@vue/compiler-sfc' | ||
import { parse } from '@vue/compiler-sfc' | ||
|
||
const cache = new Map<string, SFCDescriptor>() | ||
|
||
export function setDescriptor(filename: string, entry: SFCDescriptor) { | ||
cache.set(cleanQuery(filename), entry) | ||
} | ||
|
||
export function getDescriptor(filename: string): SFCDescriptor { | ||
filename = cleanQuery(filename) | ||
if (cache.has(filename)) { | ||
return cache.get(filename)! | ||
} | ||
|
||
// This function should only be called after the descriptor has been | ||
// cached by the main loader. | ||
// If this is somehow called without a cache hit, it's probably due to sub | ||
// loaders being run in separate threads. The only way to deal with this is to | ||
// read from disk directly... | ||
const source = fs.readFileSync(filename, 'utf-8') | ||
const { descriptor } = parse(source, { | ||
filename, | ||
sourceMap: true, | ||
}) | ||
cache.set(filename, descriptor) | ||
return descriptor | ||
} | ||
|
||
function cleanQuery(str: string) { | ||
const i = str.indexOf('?') | ||
return i > 0 ? str.slice(0, i) : str | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.