Skip to content

Instantly share code, notes, and snippets.

@jamesrr39
Last active October 3, 2023 21:21
Show Gist options
  • Save jamesrr39/459a0bfcfa2c3617b5dba856adea30bd to your computer and use it in GitHub Desktop.
Save jamesrr39/459a0bfcfa2c3617b5dba856adea30bd to your computer and use it in GitHub Desktop.
Project scaffolding

Create and run project

Start off by using the yarn create command:

yarn create vite my-project --template preact-ts
cd my-project

Switch off telemetry (optional)

yarn config set enableTelemetry 0

Add .gitignore entries as suggested by yarn:

vite.config.ts.timestamp-*.mjs

.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

Use latest yarn, with PnP enabled

yarn set version berry

Install dependencies

yarn install

Install missing/peer dependencies. These dependencies are missing from the preact-ts template. Other templates (e.g. react-ts) may be more thorough and not need this step.

yarn add --dev @babel/core @babel/plugin-transform-react-jsx-development babel-plugin-transform-hook-names

Run the project. Use --host if running yarn in a container (e.g. https://github.com/jamesrr39/yarn-contained )

yarn dev --host

Open http://localhost:5173/ and see your project running

VSCode

The above steps give us a project, but many editors are looking for a node_modules folder for dependencies & type definitions, which doesn't exist in Yarn PnP. You can install an SDK to fix the intellisense in vscode so it goes looking in the right place. Other editors are also supported.

yarn dlx @yarnpkg/sdks vscode

If you get an error with Your application tried to access color-convert, you can should install color-convert: yarn add -D color-convert, and then re-run yarn dlx @yarnpkg/sdks vscode.

Now open the settings menu:

(Ctrl + Shift + P) -> Preferences: Open Settings (UI)

Search for typescript.tsdk. It should be set to .yarn/sdks/typescript/lib - if it is not, set it to this. Note: if the package.json file is not in the root of the open project, add the path to the package.json folder (e.g. web-client/.yarn/sdks/typescript/lib)

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment