Giter Site home page Giter Site logo

preact-spa-template's Introduction

preact-spa-template

Preact single-page app starter template. This template is tuned for "SPA" sites; sites that do not need server side rendering (SSR). If you need SSR, then take a look at preact-mpa-template.

Clone repo, use node.js 14+ and run following:

npm ci
cd tests; npm ci; cd ..
npm run dev

# works with yarn and pnpm too

Features!

  • Preact + Preact hooks = 4 KB
  • Vite and all the goodies that comes with it
  • preact-router
    • Code split by pages + lazy loaded (via preact-lazy)
    • Manages browser history
    • Manage page title - so that it looks good on browser tab & browser back button history
    • 404 Screen
    • Error Screen
  • CSS Modules - with eslint typo/unused css check and autocomplete
  • ESLint and Prettier
  • Type check via JSDocs and typescript checker (tsc)
  • Yorkie git push linting hook
  • postcss-custom-media plugin
  • Vitest + Preact testing library

About Routes

You can find routes mapping (url-to-component mapping) at src/routes/routes.js.

You will notice that lazy(() => import('./file')) is used for lazy loading and bundling each page's JS into separate bundles for production.

You can also manage page titles from routes.js. title must be a string (it can have placeholders from route pattern. e.g. Orders | :orderId) or a function that which receives route info and returns a string.

Route components receives following properties about current route:

  • url: current page url
  • path: route pattern. e.g. /user/:id
  • matches: path matches (as an object). e.g: { id: 'user1' }
  • title: the title text used to set head title tag

Path redirects can be configured in src/routes/redirects.js

Path aliases

~ is short hand for src/ directory. So you don't have to do import '../../../js-file-in-src-directory'. You can just do import '~/js-file-in-src-directory'

Similarly for types, there is a shorthand alias @ to the types/ directory. import('@/RouteComponentProps')

Where to go next?

preact-spa-template's People

Contributors

munawwar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.