mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
[ci] format
This commit is contained in:
parent
d7688f05c2
commit
88974f8b40
1 changed files with 105 additions and 100 deletions
|
@ -72,7 +72,8 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
|
|||
const CSS_PLUGIN_NAME = '@astrojs/rollup-plugin-build-css';
|
||||
const CSS_MINIFY_PLUGIN_NAME = '@astrojs/rollup-plugin-build-css-minify';
|
||||
|
||||
return [{
|
||||
return [
|
||||
{
|
||||
name: CSS_PLUGIN_NAME,
|
||||
|
||||
configResolved(resolvedConfig) {
|
||||
|
@ -80,7 +81,9 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
|
|||
// The bundles before vite:css-post sees them. We can remove this code
|
||||
// after this bug is fixed: https://github.com/vitejs/vite/issues/8330
|
||||
const plugins = resolvedConfig.plugins as VitePlugin[];
|
||||
const viteCSSPostIndex = resolvedConfig.plugins.findIndex((p) => p.name === 'vite:css-post');
|
||||
const viteCSSPostIndex = resolvedConfig.plugins.findIndex(
|
||||
(p) => p.name === 'vite:css-post'
|
||||
);
|
||||
if (viteCSSPostIndex !== -1) {
|
||||
// Move our plugin to be right before this one.
|
||||
const ourIndex = plugins.findIndex((p) => p.name === CSS_PLUGIN_NAME);
|
||||
|
@ -169,17 +172,18 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
|
|||
}
|
||||
}
|
||||
},
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: CSS_MINIFY_PLUGIN_NAME,
|
||||
enforce: 'post',
|
||||
async generateBundle(_outputOptions, bundle) {
|
||||
// Minify CSS in each bundle ourselves, since server builds are not minified
|
||||
// so that the JS is debuggable. Since you cannot configure vite:css-post to minify
|
||||
// we need to do it ourselves.
|
||||
if(options.target === 'server') {
|
||||
for(const [, output] of Object.entries(bundle)) {
|
||||
if(output.type === 'asset') {
|
||||
if(output.name?.endsWith('.css') && typeof output.source === 'string') {
|
||||
if (options.target === 'server') {
|
||||
for (const [, output] of Object.entries(bundle)) {
|
||||
if (output.type === 'asset') {
|
||||
if (output.name?.endsWith('.css') && typeof output.source === 'string') {
|
||||
const { code: minifiedCSS } = await esbuild.transform(output.source, {
|
||||
loader: 'css',
|
||||
minify: true,
|
||||
|
@ -189,6 +193,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue