[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_PLUGIN_NAME = '@astrojs/rollup-plugin-build-css';
|
||||||
const CSS_MINIFY_PLUGIN_NAME = '@astrojs/rollup-plugin-build-css-minify';
|
const CSS_MINIFY_PLUGIN_NAME = '@astrojs/rollup-plugin-build-css-minify';
|
||||||
|
|
||||||
return [{
|
return [
|
||||||
|
{
|
||||||
name: CSS_PLUGIN_NAME,
|
name: CSS_PLUGIN_NAME,
|
||||||
|
|
||||||
configResolved(resolvedConfig) {
|
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
|
// 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
|
// after this bug is fixed: https://github.com/vitejs/vite/issues/8330
|
||||||
const plugins = resolvedConfig.plugins as VitePlugin[];
|
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) {
|
if (viteCSSPostIndex !== -1) {
|
||||||
// Move our plugin to be right before this one.
|
// Move our plugin to be right before this one.
|
||||||
const ourIndex = plugins.findIndex((p) => p.name === CSS_PLUGIN_NAME);
|
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,
|
name: CSS_MINIFY_PLUGIN_NAME,
|
||||||
enforce: 'post',
|
enforce: 'post',
|
||||||
async generateBundle(_outputOptions, bundle) {
|
async generateBundle(_outputOptions, bundle) {
|
||||||
// Minify CSS in each bundle ourselves, since server builds are not minified
|
// 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
|
// so that the JS is debuggable. Since you cannot configure vite:css-post to minify
|
||||||
// we need to do it ourselves.
|
// we need to do it ourselves.
|
||||||
if(options.target === 'server') {
|
if (options.target === 'server') {
|
||||||
for(const [, output] of Object.entries(bundle)) {
|
for (const [, output] of Object.entries(bundle)) {
|
||||||
if(output.type === 'asset') {
|
if (output.type === 'asset') {
|
||||||
if(output.name?.endsWith('.css') && typeof output.source === 'string') {
|
if (output.name?.endsWith('.css') && typeof output.source === 'string') {
|
||||||
const { code: minifiedCSS } = await esbuild.transform(output.source, {
|
const { code: minifiedCSS } = await esbuild.transform(output.source, {
|
||||||
loader: 'css',
|
loader: 'css',
|
||||||
minify: true,
|
minify: true,
|
||||||
|
@ -189,6 +193,7 @@ export function rollupPluginAstroBuildCSS(options: PluginOptions): VitePlugin[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}];
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue