Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: refactor ice runtime #7044

Merged
merged 11 commits into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
34 changes: 34 additions & 0 deletions examples/custom-runtime/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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',
router: {
source: '@/routes',
},
};
})
},
},
],
}));

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"
}
}
24 changes: 24 additions & 0 deletions examples/custom-runtime/runtime.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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) => {
const { basename = '', createRoutes } = options;
// Normalize pathname with leading slash
const pathname = `/${window.location.pathname.replace(basename, '').replace(/^\/+/, '')}`;

const routes = createRoutes?.({ renderMode: 'CSR' });
const Component = routes?.find(route => route.path === pathname)?.component;

ReactDOM.render(
Component ? <Component /> : <div>404</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>;
}
13 changes: 13 additions & 0 deletions examples/custom-runtime/src/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Index from './pages/index';
import Home from './pages/home';

export default () => [
{
path: '/',
component: Index,
},
{
path: '/home',
component: Home,
},
];
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"]
}
3 changes: 1 addition & 2 deletions examples/with-antd-mobile/src/store.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ComponentWithChildren } from '@ice/runtime/types';
import { useState } from 'react';
import constate from 'constate';

@@ -12,7 +11,7 @@ function useCounter() {

const [CounterProvider, useCounterContext] = constate(useCounter);

export const StoreProvider: ComponentWithChildren = ({ children }) => {
export const StoreProvider = ({ children }) => {
return <CounterProvider>{ children } </CounterProvider>;
};

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -75,5 +75,8 @@
"[email protected]": "patches/[email protected]",
"@rspack/[email protected]": "patches/@[email protected]"
}
}
},
"workspaces": [
"packages/runtime-kit"
]
}
1 change: 1 addition & 0 deletions packages/ice/package.json
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
"@ice/bundles": "workspace:*",
"@ice/route-manifest": "workspace:*",
"@ice/runtime": "workspace:^",
"@ice/runtime-kit": "workspace:^",
"@ice/shared-config": "workspace:*",
"@ice/webpack-config": "workspace:*",
"@ice/rspack-config": "workspace:*",
2 changes: 1 addition & 1 deletion packages/ice/src/bundler/config/getUrls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TaskConfig } from 'build-scripts';
import type { Config } from '@ice/shared-config/types';
import type { AppConfig } from '@ice/runtime/types';
import type { AppConfig } from '@ice/runtime-kit';
import type { Configuration as DevServerConfiguration } from 'webpack-dev-server';
import type { Configuration as RSPackDevServerConfiguration } from '@rspack/dev-server';

2 changes: 1 addition & 1 deletion packages/ice/src/bundler/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from '@ice/shared-config/types';
import type ora from '@ice/bundles/compiled/ora/index.js';
import type { Stats as WebpackStats } from '@ice/bundles/compiled/webpack/index.js';
import type { AppConfig } from '@ice/runtime/types';
import type { AppConfig } from '@ice/runtime-kit';
import type { Configuration, MultiCompiler, MultiStats } from '@rspack/core';
import type { Context as DefaultContext, TaskConfig } from 'build-scripts';
import type { ServerCompiler, GetAppConfig, GetRoutesConfig, GetDataloaderConfig, ExtendsPluginAPI } from '../types/plugin.js';
Loading
Loading