Skip to content

Commit

Permalink
[example] Update vite example
Browse files Browse the repository at this point in the history
This updates the template to the latest vitejs starter. It also fixes an
issue with Pigment initialization in dev mode by explicitly installing
prop-types and react-is and adding it to the optimizeDeps' `include`
list. This won't be an issue when we don't use prop-types in the stable
v1 release.
  • Loading branch information
Brijesh Bittu committed Nov 5, 2024
1 parent b9d3611 commit a72aaca
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 29 deletions.
25 changes: 25 additions & 0 deletions examples/pigment-css-vite-ts/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
},
},
);
6 changes: 3 additions & 3 deletions examples/pigment-css-vite-ts/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<title>Pigment CSS + Vite + TypeScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
Expand Down
12 changes: 10 additions & 2 deletions examples/pigment-css-vite-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@pigment-css/react": "latest",
"prop-types": "latest",
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"@eslint/js": "latest",
"@pigment-css/vite-plugin": "latest",
"@types/react": "latest",
"@types/react-dom": "latest",
"@vitejs/plugin-react": "latest",
"@vitejs/plugin-react-swc": "latest",
"eslint": "latest",
"eslint-plugin-react-hooks": "latest",
"eslint-plugin-react-refresh": "latest",
"globals": "latest",
"typescript": "latest",
"typescript-eslint": "latest",
"vite": "latest"
}
}
1 change: 0 additions & 1 deletion examples/pigment-css-vite-ts/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as React from 'react';
import { styled, css, keyframes } from '@pigment-css/react';

const scale = keyframes({
Expand Down
26 changes: 26 additions & 0 deletions examples/pigment-css-vite-ts/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src"]
}
21 changes: 2 additions & 19 deletions examples/pigment-css-vite-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"files": [],
"references": [{ "path": "./tsconfig.app.json" }, { "path": "./tsconfig.node.json" }]
}
21 changes: 18 additions & 3 deletions examples/pigment-css-vite-ts/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
{
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
5 changes: 4 additions & 1 deletion examples/pigment-css-vite-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import react from '@vitejs/plugin-react-swc';
import { pigment, extendTheme } from '@pigment-css/vite-plugin';

// To learn more about theming, visit https://github.com/mui/pigment-css/blob/master/README.md#theming
Expand Down Expand Up @@ -32,4 +32,7 @@ export default defineConfig({
}),
react(),
],
optimizeDeps: {
include: ['react-is', 'prop-types'],
},
});

0 comments on commit a72aaca

Please sign in to comment.