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

[WIP] feat: add icejs usage example #521

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/curly-cheetahs-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ice/pkg': patch
---

feat: support modify swc compile options
feat: enable `externalHelpers` config by default
5 changes: 5 additions & 0 deletions .changeset/fair-carrots-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/remark-react-docgen-docusaurus': major
---

feat: init plugin
5 changes: 5 additions & 0 deletions .changeset/gorgeous-frogs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg-plugin-rax-component': patch
---

chore: use Plugin type instead of deprecated PkgPlugin type
5 changes: 5 additions & 0 deletions .changeset/lemon-keys-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg-plugin-docusaurus': patch
---

fix: can not render two components in one mdx file
5 changes: 5 additions & 0 deletions .changeset/light-kangaroos-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

fix: can not parse jsx/js file
5 changes: 5 additions & 0 deletions .changeset/unlucky-radios-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

feat: add bundle.polyfill config
5 changes: 5 additions & 0 deletions .changeset/violet-lobsters-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ice/pkg': patch
---

fix: some es2017 syntax is not compatible with safari 10.1
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ packages/**/es/
packages/**/esnext/
packages/**/esm/
packages/**/es2017/
packages/**/cjs/
packages/**/build/
packages/build-plugin-component/*/template
app/main_dist/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ packages/*/es/
/packages/**/es
/packages/**/esnext
/packages/**/es2017
/packages/**/cjs
/packages/**/esm
**/node_modules
/.pnpm-debug.log
Expand Down
2 changes: 1 addition & 1 deletion examples/application/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
minimize: false,
},
resolve: {
conditionNames: ['esnext'],
conditionNames: ['es2017'],
},
entry: './index.js',
module: {
Expand Down
16 changes: 16 additions & 0 deletions examples/icejs3/ice.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defineConfig } from '@ice/app';

// The project config, see https://v3.ice.work/docs/guide/basic/config
const minify = process.env.NODE_ENV === 'production' ? 'swc' : false;
export default defineConfig(() => ({
// Set your configs here.
minify,
server: {
// onDemand: true,
format: 'esm',
},
webpack: (webpackConfig) => {
webpackConfig.resolve.conditionNames = ['es2017', '...'];
return webpackConfig;
},
}));
24 changes: 24 additions & 0 deletions examples/icejs3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@ice/lite-scaffold",
"version": "0.1.0",
"description": "ice.js 3 lite 模板",
"dependencies": {
"@ice/runtime": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"example-pkg-react-component": "workspace:*"
},
"devDependencies": {
"@ice/app": "^3.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/node": "^18.11.17",
"typescript": "^4.9.5"
},
"scripts": {
"start": "ice start",
"build": "ice build"
},
"private": true,
"originTemplate": "@ice/lite-scaffold"
}
6 changes: 6 additions & 0 deletions examples/icejs3/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineAppConfig } from 'ice';

// App config, see https://v3.ice.work/docs/guide/basic/app
export default defineAppConfig(() => ({
}));

Binary file added examples/icejs3/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/icejs3/src/document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Meta, Title, Links, Main, Scripts } from 'ice';

export default function Document() {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="description" content="ice.js 3 lite scaffold" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<Meta />
<Title />
<Links />
</head>
<body>
<Main />
<Scripts />
</body>
</html>
);
}
8 changes: 8 additions & 0 deletions examples/icejs3/src/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:root {
--primary: #3178f6;
--bg-primary: white;
}

body {
margin: 0;
}
46 changes: 46 additions & 0 deletions examples/icejs3/src/pages/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.app {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}

.app > header {
display: flex;
flex-direction: column;
align-items: center;
}

.app > header > img {
width: 120px;
}

.app > header > p {
margin: 20px 0;
text-align: center;
font-size: 2.6rem;
}

.app > main {
display: flex;
flex-direction: column;
margin: 20px 0 10px;
font-size: 0.9rem;
}

.link {
font-size: 1.2rem;
color: var(--primary);
}

.button {
outline: none;
border: none;
border-radius: 8px;
padding: 10px 35px;
background: var(--primary);
box-shadow: 0 5px 10px 0 #ddd;
color: white;
font-size: calc(10px + 2vmin);
}
19 changes: 19 additions & 0 deletions examples/icejs3/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logo from '@/assets/logo.png';
import styles from './index.module.css';
import { Button } from 'example-pkg-react-component';

export default function Home() {
return (
<div className={styles.app}>
<header>
<img src={logo} alt="logo" />
<p>
Hello ice.js 3
</p>
</header>
<main>
<Button>Normal Button</Button>
</main>
</div>
);
}
1 change: 1 addition & 0 deletions examples/icejs3/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="@ice/app/types" />
25 changes: 25 additions & 0 deletions examples/icejs3/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"baseUrl": "./",
"module": "ESNext",
"target": "ESNext",
"lib": ["DOM", "ESNext", "DOM.Iterable"],
"jsx": "react-jsx",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": false,
"importHelpers": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"],
"ice": [".ice"]
}
},
"include": ["src", ".ice"],
"exclude": ["build"]
}
3 changes: 3 additions & 0 deletions examples/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const plugin: Plugin = (api) => {
config.modifyStylesOptions.push((options) => {
return options;
});
config.modifySwcCompileOptions = (originOptions) => {
return originOptions;
};
};

onGetConfig(TaskName.BUNDLE_ES2017, bundleTaskCallback);
Expand Down
13 changes: 8 additions & 5 deletions examples/plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"rootDir": "src",
"outDir": "lib"
"module": "ESNext",
"target": "ESNext",
"jsx": "react",
"moduleResolution": "node",
"lib": ["ESNext"],
"outDir": "lib",
"skipLibCheck": true
},
"include": ["src"]
"include": ["src"],
}
5 changes: 3 additions & 2 deletions examples/rax-component/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ sidebar_label: 用法

本 Demo 演示一行文字的用法。

```jsx preview
```tsx preview
import { createElement } from 'rax';
import ExampleRaxComponent from 'example-rax-component';
import styles from './usage.module.css';

export default function App () {
return (
<div className={styles.usageContainer}>
<ExampleRaxComponent />
<ExampleRaxComponent title="XYZ" />
</div>
)
}
Expand Down
13 changes: 6 additions & 7 deletions examples/rax-component/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
"jsx": "preserve",
"jsxFactory": "createElement",
"moduleResolution": "node",
"lib": ["ES2017", "DOM"],
"sourceMap": true,
"allowJs": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"lib": ["ES2017", "DOM", "DOM.Iterable"],
"strict": true,
"skipLibCheck": true,
"paths": {
"example-rax-component": ["./src"],
"example-rax-component/*": ["./src/*"]
},
"types": ["vitest/globals"]
},
"include": ["src", "tests"],
Expand Down
10 changes: 9 additions & 1 deletion examples/react-component/build.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { defineConfig } from '@ice/pkg';
// https://pkg.ice.work/reference/config-list
export default defineConfig({
plugins: [
['@ice/pkg-plugin-docusaurus'],
[
'@ice/pkg-plugin-docusaurus',
{
remarkPlugins: [
"require('@ice/remark-react-docgen-docusaurus')",
// "[require('remark-react-docgen'), {}]",
],
},
],
['@ice/pkg-plugin-jsx-plus'],
],
transform: {
Expand Down
46 changes: 46 additions & 0 deletions examples/react-component/docs/button.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Button 组件

## 何时使用

这是一段 Button 组件使用描述

## 代码演示

### 按钮类型

按钮有两种视觉层次:主按钮、普通按钮。不同的类型可以用来区别按钮的重要程度。可以通过 `type` 属性置顶不同的视觉。

```tsx preview
import * as React from 'react';
import { Button } from 'example-pkg-react-component';

export default function App () {
return (
<div>
<Button loading={false}>Normal</Button>
<Button type="primary" loading={false}>Primary</Button>
</div>
)
}
```

### 添加事件

可以通过 `onClick` 设置点击按钮后的事件回调函数。

```tsx preview
import * as React from 'react';
import { Button } from 'example-pkg-react-component';

export default function App () {
return (
<div>
<Button onClick={() => alert('Hello World')}>Normal</Button>
</div>
)
}
```

## API

<ReactDocgenProps path="../src/components/Button/index.tsx"></ReactDocgenProps>
3 changes: 2 additions & 1 deletion examples/react-component/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
sidebar_label: 首页
sidebar_label: 快速开始
sidebar_position: 0
title: 快速开始
---

import Readme from '../README.md';
Expand Down
Loading