Skip to content

Commit da5eb98

Browse files
committed
fix: separated ui building for better dev performance
1 parent b4409ef commit da5eb98

6 files changed

Lines changed: 48 additions & 32 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ build
2828
functions
2929
.svelte-kit
3030

31-
.env.local
31+
.env.local
32+
/static/style.css

bun.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "1.0.0",
44
"scripts": {
55
"dev": "vite dev --host=0.0.0.0 --port=3002",
6+
"dev:ui": "sass src/styles/style.scss static/style.css --watch --load-path=. --quiet-deps --no-source-map",
7+
"build:ui": "sass src/styles/style.scss static/style.css --load-path=. --quiet-deps --no-source-map",
68
"build": "vite build",
79
"package": "vite package",
810
"preview": "vite preview",
@@ -43,4 +45,4 @@
4345
"esbuild",
4446
"svelte-preprocess"
4547
]
46-
}
48+
}

src/lib/components/App.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
<style lang="scss" global>
2-
@import "src/styles/style";
3-
</style>
1+
<svelte:head>
2+
{#if dev}
3+
<link rel="stylesheet" href="/style.css" />
4+
{/if}
5+
</svelte:head>
46

57
<slot />
68

79
<script>
8-
import { browser } from "$app/environment";
10+
import { browser, dev } from "$app/environment";
11+
import "@theme-style";
912
1013
if (browser) {
1114
import("$lib/init.libs");

src/styles/_empty.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is used in dev mode to avoid slow SCSS compilation.
2+
// The actual styles are loaded via static/style.css which is compiled separately.

vite.config.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sveltekit } from "@sveltejs/kit/vite";
2-
import { loadEnv } from "vite";
2+
import { defineConfig, loadEnv } from "vite";
33
import fs from "fs";
44
import path from "path";
55

@@ -63,31 +63,40 @@ function copyManifestPlugin(filename = "manifest.json") {
6363
};
6464
}
6565

66-
/** @type {import('vite').UserConfig} */
67-
const config = {
68-
plugins: [
69-
sveltekit(),
70-
copyLangFolderPlugin(),
71-
copyManifestPlugin()
72-
],
73-
css: {
74-
preprocessorOptions: {
75-
scss: {
76-
api: 'modern-compiler',
77-
quietDeps: true,
78-
silenceDeprecations: ['mixed-decls', 'color-functions', 'global-builtin', 'import'],
66+
export default defineConfig(({ command }) => {
67+
return {
68+
clearScreen: false,
69+
plugins: [sveltekit(), copyLangFolderPlugin(), copyManifestPlugin()],
70+
css: {
71+
preprocessorOptions: {
72+
scss: {
73+
api: "modern-compiler",
74+
quietDeps: true,
75+
silenceDeprecations: [
76+
"mixed-decls",
77+
"color-functions",
78+
"global-builtin",
79+
"import",
80+
],
81+
},
7982
},
8083
},
81-
},
82-
server: {
83-
proxy: {
84-
"/api": env.VITE_API_URL.replace("/api", "")
84+
server: {
85+
proxy: {
86+
"/api": env.VITE_API_URL.replace("/api", ""),
87+
},
88+
allowedHosts: true,
89+
hmr: {
90+
path: "/",
91+
},
8592
},
86-
allowedHosts: true,
87-
hmr: {
88-
path: "/",
93+
resolve: {
94+
alias: {
95+
"@theme-style":
96+
command === "serve"
97+
? path.resolve(process.cwd(), "src/styles/_empty.scss")
98+
: path.resolve(process.cwd(), "src/styles/style.scss"),
99+
},
89100
},
90-
}
91-
};
92-
93-
export default config;
101+
};
102+
});

0 commit comments

Comments
 (0)