Skip to content

Commit 7d42f72

Browse files
authored
Global stylesheets (during create-svelte depending on the chosen CSS preprocessor) (#726)
* Add a global stylesheet during create-svelte depending on the chosen CSS preprocessor * Changeset for "Add a global stylesheet during `create-svelte` depending on the chosen CSS preprocessor" * Indent `$layout.svelte` using tabs instead of spaces * Switch `global.css` to `app.css` * Make examples use `app.css`
1 parent 66ef622 commit 7d42f72

File tree

12 files changed

+38
-10
lines changed

12 files changed

+38
-10
lines changed

.changeset/wet-dingos-perform.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-svelte': patch
3+
---
4+
5+
Add a global stylesheet during create-svelte depending on the chosen CSS preprocessor
File renamed without changes.

examples/hn.svelte.dev/src/routes/$layout.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import Nav from '$lib/Nav.svelte';
44
import PreloadingIndicator from '$lib/PreloadingIndicator.svelte';
55
import ThemeToggler from '$lib/ThemeToggler.svelte';
6+
import '../app.css';
7+
68
79
$: section = $page.path.split('/')[1];
810
</script>

examples/sandbox/src/app.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:root {
2+
font-family: sans-serif;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
import '../app.css';
3+
</script>
4+
5+
<slot />

examples/sandbox/src/routes/index.svelte

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
</main>
4646

4747
<style>
48-
:root {
49-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
50-
'Open Sans', 'Helvetica Neue', sans-serif;
51-
}
52-
5348
main {
5449
text-align: center;
5550
padding: 1em;

packages/create-svelte/cli/modifications/add_css.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { bold, green } from 'kleur/colors';
22
import {
33
add_svelte_preprocess_to_config,
4+
copy_from_template_additions,
45
update_component,
56
update_package_json_dev_deps
67
} from './utils';
@@ -13,12 +14,15 @@ import {
1314
*/
1415
export default async function add_css(cwd, which) {
1516
if (which === 'css') {
17+
copy_from_template_additions(cwd, ['src', 'app.css']);
1618
console.log('You can add support for CSS preprocessors like SCSS/Less/PostCSS later.');
1719
} else if (which === 'less') {
1820
update_package_json_dev_deps(cwd, {
1921
less: '^3.0.0',
2022
'svelte-preprocess': '^4.0.0'
2123
});
24+
copy_from_template_additions(cwd, ['src', 'app.less']);
25+
update_component(cwd, 'src/routes/$layout.svelte', [['../app.css', '../app.less']]);
2226
update_component(cwd, 'src/lib/Counter.svelte', [['<style>', '<style lang="less">']]);
2327
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="less">']]);
2428
add_svelte_preprocess_to_config(cwd);
@@ -35,6 +39,8 @@ export default async function add_css(cwd, which) {
3539
sass: '^1.0.0',
3640
'svelte-preprocess': '^4.0.0'
3741
});
42+
copy_from_template_additions(cwd, ['src', 'app.scss']);
43+
update_component(cwd, 'src/routes/$layout.svelte', [['../app.css', '../app.scss']]);
3844
update_component(cwd, 'src/lib/Counter.svelte', [['<style>', '<style lang="scss">']]);
3945
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="scss">']]);
4046
add_svelte_preprocess_to_config(cwd);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:root {
2+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
3+
'Open Sans', 'Helvetica Neue', sans-serif;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:root {
2+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
3+
'Open Sans', 'Helvetica Neue', sans-serif;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:root {
2+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
3+
'Open Sans', 'Helvetica Neue', sans-serif;
4+
}

0 commit comments

Comments
 (0)