Skip to content

Commit

Permalink
fix(vike): rollback vike to vite to avoid breaking change and reuse c…
Browse files Browse the repository at this point in the history
…ode on @tsed/vite-plugin-ssr
  • Loading branch information
Romakita committed Jan 25, 2024
1 parent 2431ccc commit 60df90d
Show file tree
Hide file tree
Showing 37 changed files with 112 additions and 1,193 deletions.
12 changes: 7 additions & 5 deletions docs/tutorials/vike.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ With `vike`, you integrate tools manually and keep `architectural control`.
::: tip Note
Vike replace the `vite-plugin-ssr` package. Ts.ED provides `@tsed/vite-ssr-plugin` and `@tsed/vike` packages.
All new features will only embed to `@tsed/vike` package.

To migrate `@tsed/vite-ssr-plugin`, just replace `@tsed/vite-ssr-plugin` by `@tsed/vike` in your code and install `vike` dependency instead of `vite-plugin-ssr`.
:::

::: tip
Expand All @@ -36,7 +38,7 @@ You can read also this article over Ts.ED + Vite-plugin-ssr on Medium:

## Features

- Use `@Vike` decorator to generate a page using `vike`
- Use `@Vite` decorator to generate a page using `vite`
- Render a page using any UI framework (React, Vue, Svelte, Solid, ...)

## Quick start
Expand All @@ -46,7 +48,7 @@ You can read also this article over Ts.ED + Vite-plugin-ssr on Medium:
## Installation

```bash
npm install vike @tsed/vite-ssr-plugin vite@4 --save
npm install vike @tsed/vike vite@4 --save
```

Then edit your `Server.ts`:
Expand All @@ -56,7 +58,7 @@ import {join} from "path";
import {Configuration, Inject} from "@tsed/di";
import {PlatformApplication} from "@tsed/common";
import "@tsed/platform-express"; // /!\ keep this import
import "@tsed/vite-ssr-plugin"; // add this
import "@tsed/vike"; // add this
import "@tsed/ajv";
import "@tsed/swagger";
import {config} from "./config";
Expand Down Expand Up @@ -88,7 +90,7 @@ The start project is a monorepo (Nx) with 2 projects:
```ts
import {Constant, Controller} from "@tsed/di";
import {HeaderParams} from "@tsed/platform-params";
import {Vite} from "@tsed/vite-ssr-plugin";
import {Vite} from "@tsed/vike";
import {SwaggerSettings} from "@tsed/swagger";
import {Get, Hidden, Returns} from "@tsed/schema";

Expand Down Expand Up @@ -155,7 +157,7 @@ export function Page({docs}: PageContext & HomePageProps) {

Result:

<figure><img src="/vike-tsed.png" style="max-height: 300px; background: white"></figure>
<figure><img src="/vite-tsed.png" style="max-height: 300px; background: white"></figure>

## Add a controlled page

Expand Down
7 changes: 7 additions & 0 deletions docs/tutorials/vite-plugin-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ technology, deploy environment, Vite plugin, ...).

With `vite-plugin-ssr`, you integrate tools manually and keep `architectural control`.

::: tip Note
Vike replace the `vite-plugin-ssr` package. Ts.ED provides `@tsed/vite-ssr-plugin` and `@tsed/vike` packages.
All new features will only embed to `@tsed/vike` package.

To migrate `@tsed/vite-ssr-plugin`, just replace `@tsed/vite-ssr-plugin` by `@tsed/vike` in your code and install `vike` dependency instead of `vite-plugin-ssr`.
:::

::: tip
You can read also this article over Ts.ED + Vite-plugin-ssr on Medium:
https://romainlenzotti.medium.com/use-vite-and-ts-ed-to-build-your-website-84fb4c0d8079
Expand Down
17 changes: 10 additions & 7 deletions packages/third-parties/vike/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/vike",
"version": "7.60.0",
"description": "Vite SSR plugin package for Ts.ED framework",
"version": "7.60.1",
"description": "Vike package for Ts.ED framework",
"private": false,
"contributors": [
{
Expand Down Expand Up @@ -30,24 +30,27 @@
"sirv": ">=2.0.2"
},
"devDependencies": {
"@tsed/common": "7.60.0",
"@tsed/core": "7.60.0",
"@tsed/di": "7.60.0",
"@tsed/common": "7.60.1",
"@tsed/core": "7.60.1",
"@tsed/di": "7.60.1",
"@tsed/eslint": "7.44.1",
"@tsed/exceptions": "7.60.0",
"@tsed/exceptions": "7.60.1",
"@tsed/typescript": "7.44.1",
"eslint": "^8.12.0",
"vite": "5.0.12",
"vike": "0.4.160"
},
"peerDependencies": {
"@tsed/common": "^7.60.0",
"@tsed/common": "^7.60.1",
"vite": ">=4",
"vike": ">=0.4.160"
},
"peerDependenciesMeta": {
"@tsed/common": {
"optional": false
},
"vike": {
"optional": true
}
}
}
103 changes: 0 additions & 103 deletions packages/third-parties/vike/src/VikeModule.spec.ts

This file was deleted.

42 changes: 0 additions & 42 deletions packages/third-parties/vike/src/VikeModule.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import {VITE_SERVER} from "./services/ViteServer";
import {ViteService} from "./services/ViteService";
import {ViteModule} from "./ViteModule";

jest.mock("vite-plugin-ssr/server", () => ({
renderPage: jest.fn()
}));
jest.mock("vite", () => ({
createServer: jest.fn().mockResolvedValue({
middlewares: "middlewares",
close: jest.fn()
})
}));

async function getModuleFixture() {
const platformViews = {
registerEngine: jest.fn()
Expand Down Expand Up @@ -53,7 +43,18 @@ async function getModuleFixture() {
}

describe("ViteModule", () => {
beforeEach(() => PlatformTest.create());
beforeEach(() =>
PlatformTest.create({
imports: [
{
token: VITE_SERVER,
use: {
middlewares: jest.fn()
}
}
]
})
);
afterEach(() => PlatformTest.reset());

describe("$onInit()", () => {
Expand Down
31 changes: 0 additions & 31 deletions packages/third-parties/vike/src/decorators/vike.spec.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/third-parties/vike/src/decorators/vike.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {Store} from "@tsed/core";

import {Vite} from "./vite";

jest.mock("vite");

@Controller("/")
class ControllerTest {
@Vite()
Expand Down
14 changes: 7 additions & 7 deletions packages/third-parties/vike/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @file Automatically generated by barrelsby.
*/

export * from "./VikeModule";
export * from "./decorators/vike";
export * from "./interfaces/VikeConfig";
export * from "./interfaces/VikeRenderContext";
export * from "./ViteModule";
export * from "./decorators/vite";
export * from "./interfaces/ViteConfig";
export * from "./interfaces/ViteRenderContext";
export * from "./interfaces/interfaces";
export * from "./middlewares/VikeRendererMiddleware";
export * from "./services/VikeServer";
export * from "./services/VikeService";
export * from "./middlewares/ViteRendererMiddleware";
export * from "./services/ViteServer";
export * from "./services/ViteService";
8 changes: 0 additions & 8 deletions packages/third-parties/vike/src/interfaces/VikeConfig.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/third-parties/vike/src/interfaces/VikeRenderContext.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {Options} from "sirv";
import {Options} from "sirv";

// @ts-ignore
import type {InlineConfig} from "vite";

export interface ViteConfig extends InlineConfig {
export type ViteConfig = InlineConfig & {
enableStream?: boolean;
statics?: Omit<Options, "dev">;
stateSnapshot?(): unknown;
}
};
Loading

0 comments on commit 60df90d

Please sign in to comment.