Skip to content

Commit

Permalink
example(react-component-tsx): update example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jan 19, 2021
1 parent b9dc330 commit ca5e694
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- run: npm run build:express
- run: npm run build:hapi
- run: npm run build:react-component
- run: npm run build:react-component:doc
- run: npm run build:react-component-tsx

# - name: Build and Deploy
# uses: peaceiris/actions-gh-pages@v2.5.0
Expand Down
26 changes: 16 additions & 10 deletions example/react-component-tsx/.kktrc.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import path from 'path';
import { OptionConf } from 'kkt';
import webpack from 'webpack';
import webpack, { Configuration } from 'webpack';
import { DevServerConfigFunction, LoaderConfOptions } from 'kkt';
import WebpackDevServer from 'webpack-dev-server';
import lessModules from '@kkt/less-modules';
import rawModules from '@kkt/raw-modules';
import scopePluginOptions from '@kkt/scope-plugin-options';
import pkg from './package.json';

type Webpack = typeof webpack;

export const loaderOneOf = [require.resolve('@kkt/loader-less')];

export default (conf: webpack.Configuration, opts: OptionConf, webpack: Webpack) => {
const pkg = require(path.resolve(process.cwd(), 'package.json'));
// 获取版本
export default (conf: Configuration, env: string, options: LoaderConfOptions) => {
conf = rawModules(conf, env, { ...options });
conf = scopePluginOptions(conf, env, {
...options,
allowedFiles: [path.resolve(process.cwd(), 'README.md')],
});
conf = lessModules(conf, env, options);
// Get the project version.
conf.plugins!.push(
new webpack.DefinePlugin({
VERSION: JSON.stringify(pkg.version),
}),
);

conf.output = { ...conf.output, publicPath: './' };
return conf;
};
10 changes: 10 additions & 0 deletions example/react-component-tsx/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/*.md
**/*.svg
**/*.ejs
**/*.yml
package.json
node_modules
dist
build
lib
test
11 changes: 11 additions & 0 deletions example/react-component-tsx/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"overrides": [
{
"files": ".prettierrc",
"options": { "parser": "json" }
}
]
}
40 changes: 28 additions & 12 deletions example/react-component-tsx/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
react-component-tsx
React Component Example for TypeScript.
===

React 组件库创建一个项目,包含组件库实例预览的网站。文档与组件库放入一个工程中,全部使用 TypeScript 编写,React 组件库源文件放入 `src` 目录 ,文档网站源文件放入 `website` 目录。
Create a project for the React component library containing a website preview of the component library instance. The documents and component libraries are put into a project, all written in `TypeScript`, the component library source files are added to the `src` directory, and the document website source files are added to the `website` directory.

## 开发模式
## Open in CodeSandbox

[![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/s/github/jaywcjlove/example/react-component-tsx)

## Quick Start

```bash
npm install
```

**development**

Runs the project in development mode.

```bash
# 第一步,先运行,监听组件编译输出 .js 文件
npm run ts:watch
# 第二步,监听编译输出类型 .d.ts 文件
npm run types:watch
# 第三步,开发模式,监听编译预览网站实例
npm run doc:dev
# Step 1, run first, listen to the component compile and output the .js file
# listen for compilation output type .d.ts file
npm run watch
# Step 2, development mode, listen to compile preview website instance
npm run start
```

编译发布
**production**

Builds the app for production to the build folder.

```bash
npm run released
```
npm run build
```

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
61 changes: 44 additions & 17 deletions example/react-component-tsx/package.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,71 @@
{
"name": "@template/react-component-tsx",
"version": "2.0.0",
"version": "6.2.0",
"description": "React Component Example for TypeScript.",
"private": true,
"description": "",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"scripts": {
"doc": "ENTRYDIR=website kkt build",
"doc:dev": "ENTRYDIR=website kkt start",
"build": "npm run ts:build && npm run types:esm && npm run types:cjs && npm run css:build",
"watch": "npm run types:watch & npm run ts:watch",
"doc": "kkt build --app-src ./website",
"start": "kkt start --app-src ./website",
"build": "npm run build:lib && npm run doc",
"build:lib": "npm run ts:build && npm run types:esm && npm run types:cjs && npm run css:build",
"watch": "npm run ts:watch & npm run types:watch & npm run css:watch",
"types:build": "tsbb types --sourceRoot src --target ESNEXT",
"types:watch": "npm run types:esm -- --watch & npm run types:cjs -- --watch",
"types:esm": "npm run types:build -- --outDir ../lib/esm",
"types:cjs": "npm run types:build -- --outDir ../lib/cjs",
"css:build": "compile-less -d src -o lib/esm",
"css:watch": "compile-less -d src -o lib/esm --watch",
"ts:watch": "tsbb watch --env-name esm:dev --env-name cjs --target react",
"ts:build": "tsbb build --target react"
"ts:build": "tsbb build --target react",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\""
},
"repository": {
"type": "git",
"url": "https://github.com/kktjs/kkt.git"
},
"author": "",
"license": "MIT",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,tsx,ts,less,md,json}": [
"prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\""
]
},
"peerDependencies": {
"@babel/runtime": ">=7.10.0",
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
},
"dependencies": {
"classnames": "^2.2.6",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0"
"prop-types": "15.7.2"
},
"devDependencies": {
"@kkt/loader-less": "5.10.3",
"@types/classnames": "2.2.11",
"@types/react": "16.9.35",
"@types/react-dom": "16.9.8",
"compile-less-cli": "1.5.1",
"kkt": "5.10.3",
"@kkt/less-modules": "6.2.0",
"@kkt/raw-modules": "6.2.0",
"@kkt/scope-plugin-options": "6.2.0",
"@types/react": "17.0.0",
"@types/react-dom": "17.0.0",
"compile-less-cli": "1.6.0",
"husky": "4.3.7",
"kkt": "6.2.0",
"lint-staged": "10.5.3",
"prettier": "2.2.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"tsbb": "2.0.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand Down
34 changes: 29 additions & 5 deletions example/react-component-tsx/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>KKT</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
</html>
3 changes: 3 additions & 0 deletions example/react-component-tsx/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"template": "node"
}
26 changes: 15 additions & 11 deletions example/react-component-tsx/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import styles from './style/index.module.less';
import './style/index.less';

Expand Down Expand Up @@ -32,16 +31,21 @@ export default function Button(props: ButtonProps = {}) {
htmlType,
...others
} = props;
const cls = classnames(className, prefixCls, styles.test, {
[`${prefixCls}-${size}`]: size,
[`${prefixCls}-${type}`]: type,
[`${prefixCls}-basic`]: basic,
[`${prefixCls}-loading`]: loading, // 加载
disabled: disabled || loading, // 禁用状态
active, // 激活状态
block, // 块级元素Block level
});
/* eslint-disable */

const cls = [
className,
prefixCls,
styles.test,
size ? `${prefixCls}-${size}` : false,
type ? `${prefixCls}-${type}` : false,
basic ? `${prefixCls}-basic` : false,
loading ? `${prefixCls}-loading` : false,
disabled || loading ? 'disabled' : false,
active ? 'active' : false,
block ? 'block' : false,
]
.filter(Boolean)
.join(' ');
return (
<button {...others} disabled={disabled || loading} type={htmlType} className={cls}>
{children &&
Expand Down
59 changes: 1 addition & 58 deletions example/react-component-tsx/src/react-app-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,6 @@
/// <reference types="node" />
/// <reference types="react" />
/// <reference types="react-dom" />

declare namespace NodeJS {
interface ProcessEnv {
readonly NODE_ENV: 'development' | 'production' | 'test';
readonly PUBLIC_URL: string;
}
}

declare module '*.bmp' {
const src: string;
export default src;
}

declare module '*.gif' {
const src: string;
export default src;
}

declare module '*.jpg' {
const src: string;
export default src;
}

declare module '*.jpeg' {
const src: string;
export default src;
}

declare module '*.png' {
const src: string;
export default src;
}

declare module '*.webp' {
const src: string;
export default src;
}

declare module '*.svg' {
import * as React from 'react';

export const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;

const src: string;
export default src;
}
/// <reference types="react-scripts" />

declare module '*.module.less' {
const classes: { readonly [key: string]: string };
export default classes;
}

declare module '*.less' {
const src: string;
export default src;
}
declare module '*.module.css' {
const classes: { readonly [key: string]: string };
export default classes;
}
20 changes: 0 additions & 20 deletions example/react-component-tsx/src/style/index.css

This file was deleted.

2 changes: 1 addition & 1 deletion example/react-component-tsx/src/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
min-height: 30px;
color: #fff;
transition: background-color 0.5s, opacity 1s;
> *:not(:last-child) {
& > *:not(:last-child) {
margin-right: 5px;
}
& + &:not(.block) {
Expand Down
Loading

0 comments on commit ca5e694

Please sign in to comment.