Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function createCompilerPlugin(
// Track incremental component stylesheet builds
const stylesheetBundler = new ComponentStylesheetBundler(
styleOptions,
styleOptions.inlineStyleLanguage,
pluginOptions.incremental,
);
let sharedTSCompilationState: SharedTSCompilationState | undefined;
Expand Down Expand Up @@ -190,8 +191,8 @@ export function createCompilerPlugin(
stylesheetResult = await stylesheetBundler.bundleInline(
data,
containingFile,
// Inline stylesheets from a template style element are always CSS
containingFile.endsWith('.html') ? 'css' : styleOptions.inlineStyleLanguage,
// Inline stylesheets from a template style element are always CSS; Otherwise, use default.
containingFile.endsWith('.html') ? 'css' : undefined,
// When external runtime styles are enabled, an identifier for the style that does not change
// based on the content is required to avoid emitted JS code changes. Any JS code changes will
// invalid the output and force a full page reload for HMR cases. The containing file and order
Expand Down Expand Up @@ -490,7 +491,6 @@ export function createCompilerPlugin(
build,
stylesheetBundler,
additionalResults,
styleOptions.inlineStyleLanguage,
pluginOptions.loadResultCache,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class ComponentStylesheetBundler {
*/
constructor(
private readonly options: BundleStylesheetOptions,
private readonly defaultInlineLanguage: string,
private readonly incremental: boolean,
) {}

Expand Down Expand Up @@ -63,7 +64,12 @@ export class ComponentStylesheetBundler {
);
}

async bundleInline(data: string, filename: string, language: string, externalId?: string) {
async bundleInline(
data: string,
filename: string,
language = this.defaultInlineLanguage,
externalId?: string,
) {
// Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve
// to the actual stylesheet file path.
// TODO: Consider xxhash instead for hashing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export function setupJitPluginCallbacks(
build: PluginBuild,
stylesheetBundler: ComponentStylesheetBundler,
additionalResultFiles: Map<string, { outputFiles?: OutputFile[]; metafile?: Metafile }>,
inlineStyleLanguage: string,
loadCache?: LoadResultCache,
): void {
const root = build.initialOptions.absWorkingDir ?? '';
Expand Down Expand Up @@ -114,11 +113,7 @@ export function setupJitPluginCallbacks(
if (entry.contents === undefined) {
stylesheetResult = await stylesheetBundler.bundleFile(entry.path);
} else {
stylesheetResult = await stylesheetBundler.bundleInline(
entry.contents,
entry.path,
inlineStyleLanguage,
);
stylesheetResult = await stylesheetBundler.bundleInline(entry.contents, entry.path);
}

const { contents, outputFiles, errors, warnings, metafile, referencedFiles } =
Expand Down