Skip to content

Commit

Permalink
feat: support custom runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Jan 20, 2025
1 parent 4939b88 commit cd41e38
Show file tree
Hide file tree
Showing 27 changed files with 467 additions and 164 deletions.
1 change: 1 addition & 0 deletions examples/custom-runtime/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chrome 55
31 changes: 31 additions & 0 deletions examples/custom-runtime/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineConfig } from '@ice/app';

export default defineConfig(() => ({
ssg: false,
plugins: [
{
name: 'custom-runtime',
setup: (api) => {
// Customize the runtime
api.onGetConfig((config) => {
// Override the runtime config
config.runtime = {
exports: [
{
specifier: ['Meta', 'Title', 'Links', 'Main', 'Scripts'],
source: '@ice/runtime',
},
{
specifier: ['defineAppConfig'],
source: '@ice/runtime-kit',
},
],
source: '../runtime',
server: '@ice/runtime/server',
};
})
},
},
],
}));

23 changes: 23 additions & 0 deletions examples/custom-runtime/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@examples/custom-runtime",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "ice start",
"build": "ice build"
},
"description": "",
"author": "",
"license": "MIT",
"dependencies": {
"@ice/app": "workspace:*",
"@ice/runtime": "workspace:*",
"@ice/runtime-kit": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.2"
}
}
15 changes: 15 additions & 0 deletions examples/custom-runtime/runtime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import type { RunClientAppOptions } from '@ice/runtime-kit';
import { getAppConfig } from '@ice/runtime-kit';

import ReactDOM from 'react-dom';

const runClientApp = (options: RunClientAppOptions) => {
console.log('runClientApp', options);
ReactDOM.render(<div>Hello World</div>, document.getElementById('ice-container'));
};

export {
getAppConfig,
runClientApp,
};
Empty file.
5 changes: 5 additions & 0 deletions examples/custom-runtime/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineAppConfig } from 'ice';

export default defineAppConfig(() => ({

}));
22 changes: 22 additions & 0 deletions examples/custom-runtime/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ICE Demo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}

export default Document;
3 changes: 3 additions & 0 deletions examples/custom-runtime/src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Home() {
return <h1>home</h1>;
}
3 changes: 3 additions & 0 deletions examples/custom-runtime/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Index() {
return <h1>index</h1>;
}
1 change: 1 addition & 0 deletions examples/custom-runtime/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@ice/app/types" />
32 changes: 32 additions & 0 deletions examples/custom-runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "build",
"module": "esnext",
"target": "es6",
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"rootDir": "./",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice", "ice.config.*"],
"exclude": ["build", "public"]
}
Loading

0 comments on commit cd41e38

Please sign in to comment.