Skip to content

Commit

Permalink
Merge branch 'vite-plugin-hyperscript'
Browse files Browse the repository at this point in the history
* vite-plugin-hyperscript:
  Add types for new styling module
  Example plugin to add hyperscript capabilities to style exports
  Add vite-plugin-inspect
  • Loading branch information
davenquinn committed Jun 11, 2024
2 parents 1ebb5ea + e4ecb66 commit 400812e
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"prettier": "^2.7.1",
"sass": "^1.49.0",
"stylus": "^0.55.0",
"typescript": "^5.1.6",
"vite-plugin-rewrite-all": "^1.0.1"
"typescript": "^5.1.6"
},
"dependencies": {
"@blueprintjs/core": "^5.10.2",
Expand Down Expand Up @@ -138,6 +137,7 @@
"vike-react": "^0.4.11",
"vite": "^5.2.11",
"vite-plugin-cesium": "^1.2.22",
"vite-plugin-inspect": "^0.8.4",
"zustand": "^4.5.1"
},
"prettier": {},
Expand Down
7 changes: 6 additions & 1 deletion src/declaration.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// declaration.d.ts

import type { Hyper } from "@macrostrat/hyper";

// Union of hyper and record
type StyledHyper = Hyper & Record<string, string>;

// Style modules
declare module "*.module.styl" {
const classes: { [key: string]: string };
Expand All @@ -11,7 +16,7 @@ declare module "*.styl" {
export default content;
}

// Style modules
// Override declarations for sass module
declare module "*.module.sass" {
const classes: { [key: string]: string };
export default classes;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/map/map-interface/map-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
useContextPanelOpen,
} from "../app-state";
import Searchbar from "../components/navbar";
import styles from "./main.module.styl";
import MapContainer from "./map-view";
import { MenuPage } from "./menu";
import { info } from "console";
Expand All @@ -25,7 +24,7 @@ const ElevationChart = loadable(() => import("../components/elevation-chart"));
const InfoDrawer = loadable(() => import("../components/info-drawer"));
const Menu = loadable(() => import("./menu"));

const h = hyper.styled(styles);
import h from "./main.module.styl";

function MapView(props) {
return h(
Expand Down
28 changes: 26 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mdx from "@mdx-js/rollup";
import react from "@vitejs/plugin-react";
import path from "path";
import ssr from "vike/plugin";
import { UserConfig } from "vite";
import { UserConfig, Plugin } from "vite";
import cesium from "vite-plugin-cesium";
import pkg from "./package.json";

Expand Down Expand Up @@ -33,8 +33,31 @@ const cesiumBuildPath = path.resolve(cesiumRoot, "Cesium");

// Check if we are building for server context

const cssModuleMatcher = /\.module\.(css|scss|sass|styl)$/;

function hyperStyles(): Plugin {
return {
name: "hyper-styles",
enforce: "post",
// Post-process the output to add the hyperStyled import
transform(code, id) {
const code1 = code.replace("export default", "const styles =");
if (cssModuleMatcher.test(id)) {
//const code2 = code1 + "\nexport default styles\n";
const code3 = `import hyper from "@macrostrat/hyper";
${code1}
let h = hyper.styled(styles);
// Keep backwards compatibility with the existing default style object.
Object.assign(h, styles);
export default h;`;
//console.log(code3, id);
return code3;
}
},
};
}

const config: UserConfig = {
cacheDir: ".vite",
root: path.resolve("./src"),
resolve: {
conditions: ["typescript"],
Expand All @@ -60,6 +83,7 @@ const config: UserConfig = {
cesiumBuildPath,
cesiumBuildRootPath: cesiumRoot,
}),
hyperStyles(),
],
envDir: path.resolve(__dirname),
build: {
Expand Down
140 changes: 123 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ __metadata:
languageName: node
linkType: hard

"@antfu/utils@npm:^0.7.7":
version: 0.7.8
resolution: "@antfu/utils@npm:0.7.8"
checksum: 10/9efffb78a9683add047b0e2be96a059c3a29baee1565a2d127500bc433def25a0375c1e84c9479cbb3f1dcec797b2c1f0a24e5d85c830ea64f9a8a6a6ca5b9c3
languageName: node
linkType: hard

"@arcanis/slice-ansi@npm:^1.1.1":
version: 1.1.1
resolution: "@arcanis/slice-ansi@npm:1.1.1"
Expand Down Expand Up @@ -6650,7 +6657,7 @@ __metadata:
vike-react: "npm:^0.4.11"
vite: "npm:^5.2.11"
vite-plugin-cesium: "npm:^1.2.22"
vite-plugin-rewrite-all: "npm:^1.0.1"
vite-plugin-inspect: "npm:^0.8.4"
zustand: "npm:^4.5.1"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -8665,7 +8672,7 @@ __metadata:
languageName: node
linkType: hard

"@rollup/pluginutils@npm:^5.0.2":
"@rollup/pluginutils@npm:^5.0.2, @rollup/pluginutils@npm:^5.1.0":
version: 5.1.0
resolution: "@rollup/pluginutils@npm:5.1.0"
dependencies:
Expand Down Expand Up @@ -14131,6 +14138,15 @@ __metadata:
languageName: node
linkType: hard

"bundle-name@npm:^4.1.0":
version: 4.1.0
resolution: "bundle-name@npm:4.1.0"
dependencies:
run-applescript: "npm:^7.0.0"
checksum: 10/1d966c8d2dbf4d9d394e53b724ac756c2414c45c01340b37743621f59cc565a435024b394ddcb62b9b335d1c9a31f4640eb648c3fec7f97ee74dc0694c9beb6c
languageName: node
linkType: hard

"busboy@npm:^1.6.0":
version: 1.6.0
resolution: "busboy@npm:1.6.0"
Expand Down Expand Up @@ -15211,13 +15227,6 @@ __metadata:
languageName: node
linkType: hard

"connect-history-api-fallback@npm:^1.6.0":
version: 1.6.0
resolution: "connect-history-api-fallback@npm:1.6.0"
checksum: 10/59f013870e987f2e921218b88ad99e6b469a058ee7dd35561a360968fd4260f236b5523b7387ddec8991f9f9fbddda098f830ddc701f12c1bfb1f49d5f4b13c1
languageName: node
linkType: hard

"connect-history-api-fallback@npm:^2.0.0":
version: 2.0.0
resolution: "connect-history-api-fallback@npm:2.0.0"
Expand Down Expand Up @@ -16849,6 +16858,23 @@ __metadata:
languageName: node
linkType: hard

"default-browser-id@npm:^5.0.0":
version: 5.0.0
resolution: "default-browser-id@npm:5.0.0"
checksum: 10/185bfaecec2c75fa423544af722a3469b20704c8d1942794a86e4364fe7d9e8e9f63241a5b769d61c8151993bc65833a5b959026fa1ccea343b3db0a33aa6deb
languageName: node
linkType: hard

"default-browser@npm:^5.2.1":
version: 5.2.1
resolution: "default-browser@npm:5.2.1"
dependencies:
bundle-name: "npm:^4.1.0"
default-browser-id: "npm:^5.0.0"
checksum: 10/afab7eff7b7f5f7a94d9114d1ec67273d3fbc539edf8c0f80019879d53aa71e867303c6f6d7cffeb10a6f3cfb59d4f963dba3f9c96830b4540cc7339a1bf9840
languageName: node
linkType: hard

"default-gateway@npm:^6.0.3":
version: 6.0.3
resolution: "default-gateway@npm:6.0.3"
Expand Down Expand Up @@ -16903,6 +16929,13 @@ __metadata:
languageName: node
linkType: hard

"define-lazy-prop@npm:^3.0.0":
version: 3.0.0
resolution: "define-lazy-prop@npm:3.0.0"
checksum: 10/f28421cf9ee86eecaf5f3b8fe875f13d7009c2625e97645bfff7a2a49aca678270b86c39f9c32939e5ca7ab96b551377ed4139558c795e076774287ad3af1aa4
languageName: node
linkType: hard

"define-properties@npm:^1.1.3, define-properties@npm:^1.1.4, define-properties@npm:^1.2.0":
version: 1.2.1
resolution: "define-properties@npm:1.2.1"
Expand Down Expand Up @@ -17696,6 +17729,13 @@ __metadata:
languageName: node
linkType: hard

"error-stack-parser-es@npm:^0.1.1":
version: 0.1.4
resolution: "error-stack-parser-es@npm:0.1.4"
checksum: 10/5f3364a997489f5ce3f7d814775a32a6b98cacd366b6802c05501e2c4347b7edb3a6869f30b6026398890060e9e67d4865a801f1eee84eb8e4535bd6d423327d
languageName: node
linkType: hard

"es-abstract@npm:^1.17.2, es-abstract@npm:^1.22.1":
version: 1.22.2
resolution: "es-abstract@npm:1.22.2"
Expand Down Expand Up @@ -19238,7 +19278,7 @@ __metadata:
languageName: node
linkType: hard

"fs-extra@npm:^11.1.0":
"fs-extra@npm:^11.1.0, fs-extra@npm:^11.2.0":
version: 11.2.0
resolution: "fs-extra@npm:11.2.0"
dependencies:
Expand Down Expand Up @@ -21485,6 +21525,15 @@ __metadata:
languageName: node
linkType: hard

"is-docker@npm:^3.0.0":
version: 3.0.0
resolution: "is-docker@npm:3.0.0"
bin:
is-docker: cli.js
checksum: 10/b698118f04feb7eaf3338922bd79cba064ea54a1c3db6ec8c0c8d8ee7613e7e5854d802d3ef646812a8a3ace81182a085dfa0a71cc68b06f3fa794b9783b3c90
languageName: node
linkType: hard

"is-extglob@npm:^2.1.1":
version: 2.1.1
resolution: "is-extglob@npm:2.1.1"
Expand Down Expand Up @@ -21568,6 +21617,17 @@ __metadata:
languageName: node
linkType: hard

"is-inside-container@npm:^1.0.0":
version: 1.0.0
resolution: "is-inside-container@npm:1.0.0"
dependencies:
is-docker: "npm:^3.0.0"
bin:
is-inside-container: cli.js
checksum: 10/c50b75a2ab66ab3e8b92b3bc534e1ea72ca25766832c0623ac22d134116a98bcf012197d1caabe1d1c4bd5f84363d4aa5c36bb4b585fbcaf57be172cd10a1a03
languageName: node
linkType: hard

"is-installed-globally@npm:^0.1.0":
version: 0.1.0
resolution: "is-installed-globally@npm:0.1.0"
Expand Down Expand Up @@ -21905,6 +21965,15 @@ __metadata:
languageName: node
linkType: hard

"is-wsl@npm:^3.1.0":
version: 3.1.0
resolution: "is-wsl@npm:3.1.0"
dependencies:
is-inside-container: "npm:^1.0.0"
checksum: 10/f9734c81f2f9cf9877c5db8356bfe1ff61680f1f4c1011e91278a9c0564b395ae796addb4bf33956871041476ec82c3e5260ed57b22ac91794d4ae70a1d2f0a9
languageName: node
linkType: hard

"isarray@npm:0.0.1":
version: 0.0.1
resolution: "isarray@npm:0.0.1"
Expand Down Expand Up @@ -26378,6 +26447,18 @@ __metadata:
languageName: node
linkType: hard

"open@npm:^10.1.0":
version: 10.1.0
resolution: "open@npm:10.1.0"
dependencies:
default-browser: "npm:^5.2.1"
define-lazy-prop: "npm:^3.0.0"
is-inside-container: "npm:^1.0.0"
is-wsl: "npm:^3.1.0"
checksum: 10/a9c4105243a1b3c5312bf2aeb678f78d31f00618b5100088ee01eed2769963ea1f2dd464ac8d93cef51bba2d911e1a9c0c34a753ec7b91d6b22795903ea6647a
languageName: node
linkType: hard

"open@npm:^7.4.2":
version: 7.4.2
resolution: "open@npm:7.4.2"
Expand Down Expand Up @@ -27044,6 +27125,13 @@ __metadata:
languageName: node
linkType: hard

"perfect-debounce@npm:^1.0.0":
version: 1.0.0
resolution: "perfect-debounce@npm:1.0.0"
checksum: 10/220343acf52976947958fef3599849471605316e924fe19c633ae2772576298e9d38f02cefa8db46f06607505ce7b232cbb35c9bfd477bd0329bd0a2ce37c594
languageName: node
linkType: hard

"performance-now@npm:^0.2.0":
version: 0.2.0
resolution: "performance-now@npm:0.2.0"
Expand Down Expand Up @@ -30943,6 +31031,13 @@ __metadata:
languageName: node
linkType: hard

"run-applescript@npm:^7.0.0":
version: 7.0.0
resolution: "run-applescript@npm:7.0.0"
checksum: 10/b02462454d8b182ad4117e5d4626e9e6782eb2072925c9fac582170b0627ae3c1ea92ee9b2df7daf84b5e9ffe14eb1cf5fb70bc44b15c8a0bfcdb47987e2410c
languageName: node
linkType: hard

"run-parallel@npm:^1.1.9":
version: 1.2.0
resolution: "run-parallel@npm:1.2.0"
Expand Down Expand Up @@ -31568,7 +31663,7 @@ __metadata:
languageName: node
linkType: hard

"sirv@npm:^2.0.0":
"sirv@npm:^2.0.0, sirv@npm:^2.0.4":
version: 2.0.4
resolution: "sirv@npm:2.0.4"
dependencies:
Expand Down Expand Up @@ -34663,14 +34758,25 @@ __metadata:
languageName: node
linkType: hard

"vite-plugin-rewrite-all@npm:^1.0.1":
version: 1.0.1
resolution: "vite-plugin-rewrite-all@npm:1.0.1"
"vite-plugin-inspect@npm:^0.8.4":
version: 0.8.4
resolution: "vite-plugin-inspect@npm:0.8.4"
dependencies:
connect-history-api-fallback: "npm:^1.6.0"
"@antfu/utils": "npm:^0.7.7"
"@rollup/pluginutils": "npm:^5.1.0"
debug: "npm:^4.3.4"
error-stack-parser-es: "npm:^0.1.1"
fs-extra: "npm:^11.2.0"
open: "npm:^10.1.0"
perfect-debounce: "npm:^1.0.0"
picocolors: "npm:^1.0.0"
sirv: "npm:^2.0.4"
peerDependencies:
vite: ^2.0.0 || ^3.0.0 || ^4.0.0
checksum: 10/480997fa98b9b6a856c9c1fd915a0d830c20fa8017e53de135e03203e89bc1d33561d0a39013a8f4d27d31691d3f71d44ed9901012424ba92fc7bab27829a8b0
vite: ^3.1.0 || ^4.0.0 || ^5.0.0-0
peerDependenciesMeta:
"@nuxt/kit":
optional: true
checksum: 10/7b8997bef0f39ba4a726b47c546aeb1ecd16d5f039e6ca5d5a1b24963197ce894aee6024b456c158d22c0cf37780e38b69e164d4cc5bc6e0d6e2442c809fb9a0
languageName: node
linkType: hard

Expand Down

0 comments on commit 400812e

Please sign in to comment.