Skip to content

Instantly share code, notes, and snippets.

View bluwy's full-sized avatar
♥️
【=◈︿◈=】

Bjorn Lu bluwy

♥️
【=◈︿◈=】
View GitHub Profile
@bluwy
bluwy / publint_analysis.json
Last active May 10, 2024 04:03
Results of publint's analysis script (force push only)
{
"ansi-styles@6.2.1": 0,
"semver@7.6.2": 1,
"supports-color@9.4.0": 0,
"chalk@5.3.0": 0,
"tslib@2.6.2": 1,
"debug@4.3.4": 1,
"has-flag@5.0.1": 0,
"color-convert@2.0.1": 1,
"color-name@2.0.0": 1,
@bluwy
bluwy / rollup-optimization-research.md
Last active October 17, 2023 12:11
Rollup build optimization research

Rollup build optimization research

Rollup builds doesn't scale well in large apps. You need to increase Node's memory with --max-old-space-size=4096 to handle all the modules. This is one of Vite's highest-rated issue.

This file documents various findings and attempts to improve this issue.

How Rollup works

NOTE: I've only been reading Rollup's source code for a while, so some of these may not be accurate.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bluwy
bluwy / sequence.js
Last active March 29, 2022 03:42
Run Svelte preprocessors in the sequence they are declared
import { preprocess } from 'svelte/compiler'
/**
* @typedef {import("svelte/types/compiler/preprocess").PreprocessorGroup} PreprocessorGroup
* @param {PreprocessorGroup[]} preprocessors
* @returns {PreprocessorGroup[]}
*/
export function sequence(preprocessors) {
return preprocessors.map((preprocessor) => ({
markup({ content, filename }) {
@bluwy
bluwy / reloadImgOnFail.js
Created July 10, 2021 12:48
[Svelte] Reload image on fail to fetch
export function reloadImgOnFail(img, opts = {}) {
opts = ensureOpts(opts)
let retryCount = 0
function handleError() {
if (retryCount >= opts.maxRetryCount) {
if (opts.fallbackSrc && img.src !== opts.fallbackSrc) {
img.src = opts.fallbackSrc
}
@bluwy
bluwy / svelte-preprocess-svg.js
Last active May 30, 2021 07:15
Load SVGs as Svelte components with the least runtime overhead. Not sure if this actually improve performance?
export default function sveltePreprocessSvg() {
return {
markup({ content }) {
content = content.trim()
if (content.startsWith('<svg ') && content.endsWith('</svg>')) {
return { code: `{@html \`${content}\`}` }
} else {
return { code: content }
}
},
@bluwy
bluwy / vite.config.js
Created May 4, 2021 15:52
Import SVG as Svelte component
import fs from 'fs/promises'
import { defineConfig } from 'vite'
import svelte from '@sveltejs/vite-plugin-svelte'
export default defineConfig({
plugins: [svelteSvgPlugin(), svelte({ extensions: ['.svelte', '.svg'] })],
})
function svelteSvgPlugin() {
return {
@bluwy
bluwy / clean-snaps.sh
Created May 4, 2021 06:18
Remove unused snaps
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@bluwy
bluwy / ghaction-publish.md
Created January 24, 2021 05:25
GitHub Actions publish flow

Assuming

  1. Latest version is v1
  2. Real underlying version is v1.0.0
  3. A new release is to be published at v1.0.1 and v1

Steps

  1. Push commits
  2. Create new release for v1.0.1
@bluwy
bluwy / rollup-plugin-postcss.js
Created December 13, 2020 05:48
Rollup plugin to transform postcss files to virtual css files. Can be used with rollup-plugin-css-only to build a single css bundle
import { createFilter } from '@rollup/pluginutils'
import postcss from 'postcss'
import loadConfig from 'postcss-load-config'
/**
* @typedef {{
* include: import('@rollup/pluginutils').FilterPattern,
* exclude: import('@rollup/pluginutils').FilterPattern
* }} Options
*/