|
|
@ -1,10 +1,14 @@
|
|
|
|
import { SourceMap } from 'magic-string';
|
|
|
|
export interface Processed {
|
|
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
|
|
map?: object | string;
|
|
|
|
|
|
|
|
dependencies?: string[];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface PreprocessorGroup {
|
|
|
|
export interface PreprocessorGroup {
|
|
|
|
markup?: (options: {
|
|
|
|
markup?: (options: {
|
|
|
|
content: string;
|
|
|
|
content: string;
|
|
|
|
filename: string;
|
|
|
|
filename: string;
|
|
|
|
}) => { code: string; map?: SourceMap | string; dependencies?: string[] };
|
|
|
|
}) => Processed;
|
|
|
|
style?: Preprocessor;
|
|
|
|
style?: Preprocessor;
|
|
|
|
script?: Preprocessor;
|
|
|
|
script?: Preprocessor;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -13,13 +17,7 @@ export type Preprocessor = (options: {
|
|
|
|
content: string;
|
|
|
|
content: string;
|
|
|
|
attributes: Record<string, string | boolean>;
|
|
|
|
attributes: Record<string, string | boolean>;
|
|
|
|
filename?: string;
|
|
|
|
filename?: string;
|
|
|
|
}) => { code: string; map?: SourceMap | string; dependencies?: string[] };
|
|
|
|
}) => Processed;
|
|
|
|
|
|
|
|
|
|
|
|
interface Processed {
|
|
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
|
|
map?: SourceMap | string;
|
|
|
|
|
|
|
|
dependencies?: string[];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function parse_attributes(str: string) {
|
|
|
|
function parse_attributes(str: string) {
|
|
|
|
const attrs = {};
|
|
|
|
const attrs = {};
|
|
|
@ -85,7 +83,7 @@ export default async function preprocess(
|
|
|
|
const style = preprocessors.map(p => p.style).filter(Boolean);
|
|
|
|
const style = preprocessors.map(p => p.style).filter(Boolean);
|
|
|
|
|
|
|
|
|
|
|
|
for (const fn of markup) {
|
|
|
|
for (const fn of markup) {
|
|
|
|
const processed: Processed = await fn({
|
|
|
|
const processed = await fn({
|
|
|
|
content: source,
|
|
|
|
content: source,
|
|
|
|
filename
|
|
|
|
filename
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -98,7 +96,7 @@ export default async function preprocess(
|
|
|
|
source,
|
|
|
|
source,
|
|
|
|
/<script(\s[^]*?)?>([^]*?)<\/script>/gi,
|
|
|
|
/<script(\s[^]*?)?>([^]*?)<\/script>/gi,
|
|
|
|
async (match, attributes = '', content) => {
|
|
|
|
async (match, attributes = '', content) => {
|
|
|
|
const processed: Processed = await fn({
|
|
|
|
const processed = await fn({
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
attributes: parse_attributes(attributes),
|
|
|
|
attributes: parse_attributes(attributes),
|
|
|
|
filename
|
|
|
|
filename
|
|
|
|