[ci] format
This commit is contained in:
parent
77354c89bd
commit
5c9312620d
4 changed files with 16 additions and 16 deletions
|
@ -76,7 +76,7 @@ export async function build(opts: ScanBasedBuildOptions): Promise<RollupOutput |
|
||||||
}),
|
}),
|
||||||
rollupPluginAstroBuildCSS({
|
rollupPluginAstroBuildCSS({
|
||||||
internals,
|
internals,
|
||||||
legacy: true
|
legacy: true,
|
||||||
}),
|
}),
|
||||||
...(viteConfig.plugins || []),
|
...(viteConfig.plugins || []),
|
||||||
],
|
],
|
||||||
|
|
|
@ -146,7 +146,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp
|
||||||
vitePluginPages(opts, internals),
|
vitePluginPages(opts, internals),
|
||||||
rollupPluginAstroBuildCSS({
|
rollupPluginAstroBuildCSS({
|
||||||
internals,
|
internals,
|
||||||
legacy: false
|
legacy: false,
|
||||||
}),
|
}),
|
||||||
...(viteConfig.plugins || []),
|
...(viteConfig.plugins || []),
|
||||||
// SSR needs to be last
|
// SSR needs to be last
|
||||||
|
@ -200,7 +200,7 @@ async function clientBuild(opts: StaticBuildOptions, internals: BuildInternals,
|
||||||
vitePluginHoistedScripts(astroConfig, internals),
|
vitePluginHoistedScripts(astroConfig, internals),
|
||||||
rollupPluginAstroBuildCSS({
|
rollupPluginAstroBuildCSS({
|
||||||
internals,
|
internals,
|
||||||
legacy: false
|
legacy: false,
|
||||||
}),
|
}),
|
||||||
...(viteConfig.plugins || []),
|
...(viteConfig.plugins || []),
|
||||||
],
|
],
|
||||||
|
|
|
@ -53,17 +53,17 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
||||||
const { internals, legacy } = options;
|
const { internals, legacy } = options;
|
||||||
const styleSourceMap = new Map<string, string>();
|
const styleSourceMap = new Map<string, string>();
|
||||||
|
|
||||||
function * walkStyles(ctx: PluginContext, id: string, seen = new Set<string>()): Generator<[string, string], void, unknown> {
|
function* walkStyles(ctx: PluginContext, id: string, seen = new Set<string>()): Generator<[string, string], void, unknown> {
|
||||||
seen.add(id);
|
seen.add(id);
|
||||||
if(styleSourceMap.has(id)) {
|
if (styleSourceMap.has(id)) {
|
||||||
yield [id, styleSourceMap.get(id)!];
|
yield [id, styleSourceMap.get(id)!];
|
||||||
}
|
}
|
||||||
|
|
||||||
const info = ctx.getModuleInfo(id);
|
const info = ctx.getModuleInfo(id);
|
||||||
if(info) {
|
if (info) {
|
||||||
for(const importedId of info.importedIds) {
|
for (const importedId of info.importedIds) {
|
||||||
if(!seen.has(importedId)) {
|
if (!seen.has(importedId)) {
|
||||||
yield * walkStyles(ctx, importedId, seen);
|
yield* walkStyles(ctx, importedId, seen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,15 +76,15 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
||||||
* to prevent adding all styles to all pages.
|
* to prevent adding all styles to all pages.
|
||||||
*/
|
*/
|
||||||
async function addStyles(this: PluginContext) {
|
async function addStyles(this: PluginContext) {
|
||||||
for(const id of this.getModuleIds()) {
|
for (const id of this.getModuleIds()) {
|
||||||
if(hasPageDataByViteID(internals, id)) {
|
if (hasPageDataByViteID(internals, id)) {
|
||||||
let pageStyles = '';
|
let pageStyles = '';
|
||||||
for(const [_styleId, styles] of walkStyles(this, id)) {
|
for (const [_styleId, styles] of walkStyles(this, id)) {
|
||||||
pageStyles += styles;
|
pageStyles += styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pages with no styles, nothing more to do
|
// Pages with no styles, nothing more to do
|
||||||
if(!pageStyles) continue;
|
if (!pageStyles) continue;
|
||||||
|
|
||||||
const { code: minifiedCSS } = await esbuild.transform(pageStyles, {
|
const { code: minifiedCSS } = await esbuild.transform(pageStyles, {
|
||||||
loader: 'css',
|
loader: 'css',
|
||||||
|
@ -161,7 +161,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
||||||
},
|
},
|
||||||
|
|
||||||
async renderChunk(_code, chunk) {
|
async renderChunk(_code, chunk) {
|
||||||
if(!legacy) return null;
|
if (!legacy) return null;
|
||||||
|
|
||||||
let chunkCSS = '';
|
let chunkCSS = '';
|
||||||
let isPureCSS = true;
|
let isPureCSS = true;
|
||||||
|
@ -212,7 +212,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin {
|
||||||
const emptyChunkRE = new RegExp(opts.format === 'es' ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";\n?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);\n?`, 'g');
|
const emptyChunkRE = new RegExp(opts.format === 'es' ? `\\bimport\\s*"[^"]*(?:${emptyChunkFiles})";\n?` : `\\brequire\\(\\s*"[^"]*(?:${emptyChunkFiles})"\\);\n?`, 'g');
|
||||||
|
|
||||||
// Crawl the module graph to find CSS chunks to create
|
// Crawl the module graph to find CSS chunks to create
|
||||||
if(!legacy) {
|
if (!legacy) {
|
||||||
await addStyles.call(this);
|
await addStyles.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ describe('Page-level styles', () => {
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Doesn\'t add page styles for a page without style imports', async () => {
|
it("Doesn't add page styles for a page without style imports", async () => {
|
||||||
let html = await fixture.readFile('/index.html');
|
let html = await fixture.readFile('/index.html');
|
||||||
let $ = await cheerioLoad(html);
|
let $ = await cheerioLoad(html);
|
||||||
expect($('link').length).to.equal(0);
|
expect($('link').length).to.equal(0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue