sku

repository·master·Indexed 19 days ago

https://github.com/seek-oss/sku

A front-end development toolkit providing a zero-config environment powered by Webpack, Babel, Vanilla Extract, ESLint, Prettier, and Jest. It includes a suite of tools such as @sku-lib/create for project scaffolding, @sku-lib/codemod for automated code transformations, and pnpm-plugin-sku for automating recommended PNPM settings.

Tokens
55.2K
Snippets
225
Records
280
Agent score
67%

What's inside sku

  1. Overview of the sku toolkit

    master

    sku is a front-end development toolkit designed for zero-config builds, local development, testing, and linting. It provides sensible defaults for production-ready environments and is specifically tuned for use within SEEK ecosystems.

    Key features include:

    • Zero-config builds: Out-of-the-box support for Webpack or Vite. You only need to add a sku.config file when opting into advanced configurations.
    • Production readiness: Built-in support for code splitting, multi-site theming, and Content Security Policy (CSP).
    • Integrated quality tools: Pre-configured support for ESLint, Prettier, TypeScript, and Vitest.
    • SEEK ecosystem compatibility: First-class support for Braid Design System, Vanilla Extract, and Vocab.
  2. Use @sku-lib/babel-plugin-display-name to ensure React displayName is present in production

    master

    The @sku-lib/babel-plugin-display-name Babel plugin ensures that the displayName property is added to React components in all environments.

    Unlike the original MUI version, which wraps the displayName addition in a process.env.NODE_ENV check (omitting it in production), this fork removes that check. Use this plugin if your application or debugging tools require the displayName property to be present even in production builds.

  3. URL structure and redirection rules for the sku docs site

    master

    The sku documentation site follows specific URL patterns for content delivery and legacy compatibility. Content is served without a /docs prefix, and the site handles redirects for older path structures and Docsify-style hash routes.

    URL Structure

    Content located in the VitePress srcDir: 'docs' is published at the root of the documentation path. For example, a file at site/docs/support.md is accessible at /support (not /docs/support).

    Legacy Path Redirects

    To maintain backward compatibility, the site redirects legacy paths to the new structure:

    • /sku/docs or /sku/docs/<path> is redirected to /sku/ or /sku/<path>.
    • Query parameters and hashes are preserved during this redirect.

    Docsify Hash Route Redirects

    For users arriving via old Docsify hash routes (e.g., #/./docs/vite?id=foo), the site performs the following transformation:

    1. Strips the leading docs/ from the hash path.
    2. Maps the id= query parameter to a URL fragment (hash).
    3. Redirects to the clean path (e.g., #/./docs/vite?id=foo becomes /sku/vite#foo).
  4. Vite support in Sku

    master

    Since v15, sku supports Vite as an alternative to the Webpack bundler.

    Limitations:

    • Vite support is currently only available for static applications (SSG).
    • Supported commands: sku start and sku build.
    • sku serve is also available as it is bundler agnostic.

    Library Mode: Building libraries with Webpack is currently supported, but this feature is planned for deprecation and will not be supported with Vite. A migration guide for sku libraries will be provided in the future.

  5. Handle Vitest globals and testing library cleanup

    master

    By default, sku uses Vitest's configuration where global test APIs (like describe, it, expect) are disabled. You must explicitly import these from vitest in your test files.

    Additionally, because globals are disabled, libraries like @testing-library/react will not perform automatic DOM cleanup. You must manually add cleanup to your setupTests file using afterEach from vitest.

    // myFunction.test.ts
    import { describe, expect, it } from 'vitest';
    
    // test-setup.ts
    import '@testing-library/jest-dom/vitest';
    import { cleanup } from '@testing-library/react';
    import { afterEach } from 'vitest';
    
    afterEach(cleanup);
  6. Configure local development hosts in sku

    master

    You can manage local development hostnames using the following mechanisms:

    • Automatic Resolution: Use *.localhost or localhost to avoid manual /etc/hosts configuration and suppress warnings.
    • sku setup-hosts: When running this command, sku will continue to write .localhost hosts to your hosts file (except for the exact localhost hostname, which is skipped to avoid duplication).
    • HTTPS Support: For browsers like Safari that may still require local SSL, existing httpsDevServer and local HTTPS behaviors remain fully supported and functional.
  7. Modify internal tool configurations (ESLint, Jest, TS, Vitest, Webpack, Vite)

    master

    The dangerouslySet*Config functions allow you to modify sku's internal configurations for ESLint, Jest, TypeScript, Vitest, Webpack, or Vite.

    WARNING: These should only be used in exceptional circumstances. sku provides no guarantees that its internal configurations will remain compatible with your customizations. It is your responsibility to ensure compatibility.

    Available Functions:

    • dangerouslySetESLintConfig: Modifies ESLint configuration. Returns Linter.Config[].
    • dangerouslySetJestConfig: Modifies Jest configuration.
    • dangerouslySetTSConfig: Modifies TypeScript configuration.
    • dangerouslySetVitestConfig: Modifies Vitest configuration.
    • dangerouslySetWebpackConfig: (Webpack only) Modifies Webpack configuration. Runs twice (once for client, once for server|render). Check config.name to distinguish.
    • dangerouslySetViteConfig: (Vite only) Modifies Vite configuration. Runs twice (once for client, once for render). Check env.mode to distinguish.
    import type { SkuConfig } from 'sku';
    import customPlugin from 'custom-eslint-plugin';
    
    export default {
      // Example: Modifying ESLint
      dangerouslySetESLintConfig: (skuEslintConfig) => [
        ...skuEslintConfig,
        {
          plugins: { customPlugin },
          rules: { 'customPlugin/rule1': 'warn' },
        },
      ],
    
      // Example: Modifying Vite (returns partial config for deep merge)
      dangerouslySetViteConfig: (_config, _env) => ({
        resolve: {
          alias: { foo: 'bar' },
        },
      }),
    } satisfies SkuConfig;
  8. How SVGs are handled in sku

    master

    Unlike other images, imported SVGs are treated as raw strings containing optimized (via SVGO) markup rather than URLs. You can render this markup using dangerouslySetInnerHTML in React.

    Important: To ensure consistent behavior between Webpack and Vite, it is recommended to use query parameters (url, raw, or inline) when importing SVGs. Without these, Webpack returns optimized markup while Vite treats them as standard image assets (URLs/data URLs).

    import svgMarkup from './icon.svg';
    
    const MySvgComponent = () => {
      return <div dangerouslySetInnerHTML={{ __html: svgMarkup }} />;
    };
  9. Automatic assertion removal in production

    master

    By default, sku uses babel-plugin-unassert to remove assertions from your production builds. This allows you to use expensive runtime checks in development without impacting production performance.

    Supported Assertion Functions:

    • invariant
    • assert

    Supported Libraries:

    • tiny-invariant (Recommended)
    • assert (Browser port)
    • node:assert (Node.js built-in)
    • assert (Node.js built-in)
    import React from 'react';
    import assert from 'assert';
    
    export const Rating = ({ rating }: { rating: number }) => {
      assert(rating >= 0 && rating <= 5, 'Rating must be between 0 and 5');
    
      return <div...>{
    }
    import React from 'react';
    
    export const Rating = ({ rating }) => {
      return <div...>;
    }
  10. Use language hierarchy and extensions

    master

    To avoid duplicating translations for similar languages, you can use language extensions. If a language extends another, sku will automatically copy any missing translations from the base language to the specific language.

    Example: An en-AU language can extend en to only provide specific spelling differences (like colour vs color).

    Warning: Avoid using extensions if you are not certain you want the base language's translations to fall back to production, as sku cannot distinguish between an intentional omission and a mistake.

    // Example of a language object designating a parent
    { name: "en-AU", extends: "en" }
  11. Understand the SSR development server architecture

    master

    During development, sku runs two distinct services:

    1. Dev Server: Responsible for serving static assets. It acts as the primary entrypoint and proxies requests that do not match known static routes to the SSR service. This simulates a production reverse-proxy environment and avoids CORS issues.
    2. SSR Service: Runs your application's server code.

    If you need to proxy other traffic, such as API requests, you should use [Dev Server Middleware].

  12. Understand sku entry points: Render, Server, and Client

    master

    sku applications rely on specific entry points depending on their rendering strategy:

    • Render Entry: Used in static rendering. It returns an HTML string representing routes, sites, and environments. It functions like a server render that executes at build time.
    • Server Entry: Used in SSR only projects. It handles HTTP requests (using express) and allows for router middleware. It is similar to the Render entry but operates during request time.
    • Client Entry: The entry point for all browser-side code. This is where you hydrate your React application and configure state management.