Skip to content

Instantly share code, notes, and snippets.

View theetrain's full-sized avatar
💻
Making the symbols work

Enrico Sacchetti theetrain

💻
Making the symbols work
View GitHub Profile
@theetrain
theetrain / auto-import-css.md
Created June 21, 2024 02:42
Automatically import library CSS with Svelte components

Cool Vite thing I learned today; @import in .css files will be inlined at build time.

/* main.css */
@import url('variables.css');
@import url('normalize.css');

This becomes a single CSS file in the production build; and if you happen to add it to a shared library (npm package), you can have it auto-import global styles along with Svelte components.

@theetrain
theetrain / +page.server.js
Last active May 17, 2024 15:01
MaybStream
import { maybeStream } from '$lib/utils'
/** @type {import('./$types').PageServerLoad} */
export async function load({ isDataRequest }) {
const combinationResponse = maybeStream(pretendAPI(), { isDataRequest })
const otherCombinationResponse = maybeStream(pretendAPI(), { isDataRequest })
let [combination, other] = await Promise.all([
combinationResponse,
otherCombinationResponse
@theetrain
theetrain / +page.server.ts
Created September 12, 2023 02:01
PocketBase JavaScript SDK back-end connection (SvelteKit example)
import { connect } from '$lib/server/pbclient'
import { redirect, type Actions } from '@sveltejs/kit'
export const actions = {
create: async ({ request, cookies }) => {
const data = await request.formData()
const post = [...data.entries()]
const pb = await connect()
@theetrain
theetrain / .eslintrc.json
Created August 28, 2023 14:23
Svelte ESLint config
{
"root": true,
"extends": ["prettier", "standard"],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"rules": {
"arrow-parens": ["error", "as-needed"],
"operator-linebreak": ["error", "before"],
"no-trailing-spaces": [
"error",
@theetrain
theetrain / ui-chooser.mmd
Last active May 28, 2023 16:00
Choosing a UI library (Svelte Edition)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theetrain
theetrain / App.svelte
Created January 20, 2023 03:47
Svelte custom element
<svelte:options tag="my-app" />
<workgroup-page />
@theetrain
theetrain / Dockerfile
Created December 17, 2022 22:31
Node Dockerfile
FROM node:18.12.1-alpine3.16 as nodebuilder
WORKDIR /app
COPY . .
RUN npm i
RUN npm run build
CMD npm i && npm start
@theetrain
theetrain / server.js
Created July 16, 2021 16:51
HTTPS-enabled NextJS server
// NextJS custom server with HTTPS
// Note, you must generate certificates on your own
const express = require('express')
const nextJs = require('next')
const https = require('https')
const fs = require('fs')
const APP_ENV = process.env.APP_ENV || 'development'
const port = parseInt(process.env.PORT, 10) || 3000
@theetrain
theetrain / docker-compose.yml
Last active December 10, 2020 18:43
For Jekyll development. All you need to run is `docker-compose up`!
# Port 3000 is for manually logging in and using `netlify dev` if you use the CLI for leveraging secrets
# This includes --livereload to refresh the page when there are file changes
# Runs on localhost:4000
version: "3.8"
services:
dev:
image: jekyll/jekyll:4
ports:
- 4000:4000