-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve client api implementation
fix: #25
- Loading branch information
Showing
4 changed files
with
49 additions
and
70 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
// so that users or themes can: | ||
// import { useStaticData } from "vite-plugin-react-pages/client" | ||
|
||
// This module can be imported by theme, which may be optimized by vite | ||
// so this module must be optimizable too. | ||
// should not contains "import initialPages from '/@react-pages/pages'", | ||
// otherwise vite will throw error when optimizing theme: Could not resolve "/@react-pages/pages" | ||
// So this module can't import vite-pages core. | ||
// Otherwise vite will try to optimize vite-pages core during dev. | ||
|
||
import type { UseStaticData } from './clientTypes' | ||
|
||
const globalObject: any = typeof window !== 'undefined' ? window : global | ||
|
||
// users can import { useStaticData } from "vite-plugin-react-pages/client" | ||
// access globalObject['__vite_pages_use_static_data'] lazily | ||
export const useStaticData: UseStaticData = (...params: any[]) => { | ||
const actualUseStaticData: any = globalObject['__vite_pages_use_static_data'] | ||
return actualUseStaticData(...params) | ||
} | ||
|
||
export type { Theme } from './clientTypes' | ||
// we don't use ./_state_declaration because vite-plugin-react-pages/_state_declaration is an entry of vite optimization | ||
export { useStaticData } from 'vite-plugin-react-pages/_state_declaration' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters