Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global stylesheets (during create-svelte depending on the chosen CSS preprocessor) #726

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wet-dingos-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Add a global stylesheet during create-svelte depending on the chosen CSS preprocessor
2 changes: 2 additions & 0 deletions examples/hn.svelte.dev/src/routes/$layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import Nav from '$lib/Nav.svelte';
import PreloadingIndicator from '$lib/PreloadingIndicator.svelte';
import ThemeToggler from '$lib/ThemeToggler.svelte';
import '../app.css';


$: section = $page.path.split('/')[1];
</script>
Expand Down
3 changes: 3 additions & 0 deletions examples/sandbox/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
font-family: sans-serif;
}
5 changes: 5 additions & 0 deletions examples/sandbox/src/routes/$layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import '../app.css';
</script>

<slot />
5 changes: 0 additions & 5 deletions examples/sandbox/src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@
</main>

<style>
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
}

main {
text-align: center;
padding: 1em;
Expand Down
6 changes: 6 additions & 0 deletions packages/create-svelte/cli/modifications/add_css.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { bold, green } from 'kleur/colors';
import {
add_svelte_preprocess_to_config,
copy_from_template_additions,
update_component,
update_package_json_dev_deps
} from './utils';
Expand All @@ -13,12 +14,15 @@ import {
*/
export default async function add_css(cwd, which) {
if (which === 'css') {
copy_from_template_additions(cwd, ['src', 'app.css']);
console.log('You can add support for CSS preprocessors like SCSS/Less/PostCSS later.');
} else if (which === 'less') {
update_package_json_dev_deps(cwd, {
less: '^3.0.0',
'svelte-preprocess': '^4.0.0'
});
copy_from_template_additions(cwd, ['src', 'app.less']);
update_component(cwd, 'src/routes/$layout.svelte', [['../app.css', '../app.less']]);
update_component(cwd, 'src/lib/Counter.svelte', [['<style>', '<style lang="less">']]);
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="less">']]);
add_svelte_preprocess_to_config(cwd);
Expand All @@ -35,6 +39,8 @@ export default async function add_css(cwd, which) {
sass: '^1.0.0',
'svelte-preprocess': '^4.0.0'
});
copy_from_template_additions(cwd, ['src', 'app.scss']);
update_component(cwd, 'src/routes/$layout.svelte', [['../app.css', '../app.scss']]);
update_component(cwd, 'src/lib/Counter.svelte', [['<style>', '<style lang="scss">']]);
update_component(cwd, 'src/routes/index.svelte', [['<style>', '<style lang="scss">']]);
add_svelte_preprocess_to_config(cwd);
Expand Down
4 changes: 4 additions & 0 deletions packages/create-svelte/template-additions/src/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
}
4 changes: 4 additions & 0 deletions packages/create-svelte/template-additions/src/app.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
}
4 changes: 4 additions & 0 deletions packages/create-svelte/template-additions/src/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
}
5 changes: 5 additions & 0 deletions packages/create-svelte/template/src/routes/$layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import '../app.css';
</script>

<slot />
5 changes: 0 additions & 5 deletions packages/create-svelte/template/src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
</main>

<style>
:root {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
'Open Sans', 'Helvetica Neue', sans-serif;
}

main {
text-align: center;
padding: 1em;
Expand Down