mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-22 12:27:29 +01:00
6c66680919
* chore: bump typescript to 5.5 * try to revert non-typescript-related changes to lockfile --------- Co-authored-by: Conduitry <git@chor.date>
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
import { sveltekit } from '@sveltejs/kit/vite';
|
|
import { browserslistToTargets } from 'lightningcss';
|
|
import { readFile } from 'node:fs/promises';
|
|
import browserslist from 'browserslist';
|
|
|
|
/** @type {import('vite').PluginOption[]} */
|
|
const plugins = [raw(['.ttf']), sveltekit()];
|
|
|
|
// Only enable sharp if we're not in a webcontainer env
|
|
if (!process.versions.webcontainer) {
|
|
const { imagetools } = await import('vite-imagetools');
|
|
|
|
const plugin = imagetools({
|
|
defaultDirectives: (url) => {
|
|
if (url.searchParams.has('big-image')) {
|
|
return new URLSearchParams('w=640;1280;2560;3840&format=avif;webp;png&as=picture');
|
|
}
|
|
|
|
return new URLSearchParams();
|
|
}
|
|
});
|
|
|
|
plugins.push(/** @type {import('vite').PluginOption} */ (/** @type {unknown} */ (plugin)));
|
|
}
|
|
|
|
/**
|
|
* @param {string[]} ext
|
|
* @returns {import("vite").Plugin}
|
|
*/
|
|
function raw(ext) {
|
|
return {
|
|
name: 'vite-plugin-raw',
|
|
async transform(_, id) {
|
|
if (ext.some((e) => id.endsWith(e))) {
|
|
const buffer = await readFile(id);
|
|
return { code: `export default ${JSON.stringify(buffer)}`, map: null };
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
/** @type {import('vite').UserConfig} */
|
|
const config = {
|
|
logLevel: 'info',
|
|
css: {
|
|
transformer: 'lightningcss',
|
|
lightningcss: {
|
|
targets: browserslistToTargets(browserslist(['>0.2%', 'not dead']))
|
|
}
|
|
},
|
|
build: {
|
|
cssMinify: 'lightningcss'
|
|
},
|
|
plugins,
|
|
optimizeDeps: {
|
|
exclude: ['@sveltejs/site-kit', '@sveltejs/repl']
|
|
},
|
|
ssr: { noExternal: ['@sveltejs/site-kit', '@sveltejs/repl'] },
|
|
server: {
|
|
fs: {
|
|
strict: false
|
|
}
|
|
}
|
|
};
|
|
|
|
export default config;
|