Skip to content

Instantly share code, notes, and snippets.

View epreston's full-sized avatar

Ed Preston epreston

View GitHub Profile
@epreston
epreston / basic.madgerc
Created April 28, 2023 18:13
madgerc - simple configuration for madge
{
"layout": "dot",
"rankdir": "LR",
"fontName": "Courier",
"fontSize": "16",
"detectiveOptions": {
"es6": {
"skipTypeImports": true
},
"ts": {
@epreston
epreston / IntersectionObserverMock.js
Created April 28, 2023 18:02
IntersectionObserver - simple mock for vitest
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
takeRecords: vi.fn(),
unobserve: vi.fn(),
}))
@epreston
epreston / dev.vite.config.js
Last active April 27, 2023 18:12
vite.config.js - example combo vite / vitest config, enforcing modern build target, test setup
// vite.config.js
// import types for vitest config autocomplete
/// <reference types="vitest" />
import { defineConfig } from 'vite';
export default defineConfig({
// assetsInclude: ['**/*.gltf', '**/*.glb', '**/*.m4a'], // additional asset types
// define: {
@epreston
epreston / basic.prettierrc.json
Created April 27, 2023 16:41
.prettierrc.json - JavaScript prettier config , 120 line width, tabwidth 2 space, semi, single quote, arrowParens, comma
{
"$schema": "http://json.schemastore.org/prettierrc",
"arrowParens": "always",
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"editorconfig": true,
"printWidth": 120
}
@epreston
epreston / advanced.gitignore
Created April 27, 2023 16:37
.gitignore - a more complete template for web development
# Add any directories, files, or patterns you don't want to be tracked by version control
# Windows and OSX Specific System Files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
*.swp
ehthumbs.db
@epreston
epreston / basic.eslintrc.json
Last active August 6, 2023 18:16
eslintrc.json - root template, config and rules for prettier, helpful extras
{
"root": true,
"env": {
"es2022": true,
"browser": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
@epreston
epreston / global.d.ts
Created April 27, 2023 16:30
global.d.ts - required to properly configure vite projects with some examples
// global.d.ts
/// <reference types="vite/client" />
// additional import types not included in vite/client
// declare module '*.m4a' {
// const src: string
// export default src
// }
@epreston
epreston / jsconfig.json
Created April 27, 2023 16:26
jsconfig.json - type checking modern js only projects in vscode typescript support
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
@epreston
epreston / basic.prettierignore
Last active April 27, 2023 16:18
basic .prettierignore - exclude the final build products from formatting
dist
@epreston
epreston / queueMicrotask.js
Created April 27, 2023 16:12
queueMicrotask - usage in synthetic events
// see: https://twitter.com/diegohaz/status/1530662445240426496
const anotherElement = document.querySelector('#anotherElement');
function onClick() {
// BAD - Focus will fire on another element before the
// click event finishes bubbling. You may get events
// in the wrong order on parent elements.
anotherElement.focus();