diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6a2cbb6..935e3d42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/example/react-component-tsx/.kktrc.ts b/example/react-component-tsx/.kktrc.ts index fb414edf..d0d7c621 100644 --- a/example/react-component-tsx/.kktrc.ts +++ b/example/react-component-tsx/.kktrc.ts @@ -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; }; diff --git a/example/react-component-tsx/.prettierignore b/example/react-component-tsx/.prettierignore new file mode 100644 index 00000000..d9b95702 --- /dev/null +++ b/example/react-component-tsx/.prettierignore @@ -0,0 +1,10 @@ +**/*.md +**/*.svg +**/*.ejs +**/*.yml +package.json +node_modules +dist +build +lib +test diff --git a/example/react-component-tsx/.prettierrc b/example/react-component-tsx/.prettierrc new file mode 100644 index 00000000..764fbde2 --- /dev/null +++ b/example/react-component-tsx/.prettierrc @@ -0,0 +1,11 @@ +{ + "singleQuote": true, + "trailingComma": "all", + "printWidth": 120, + "overrides": [ + { + "files": ".prettierrc", + "options": { "parser": "json" } + } + ] +} diff --git a/example/react-component-tsx/README.md b/example/react-component-tsx/README.md index f2af866f..9d449f56 100644 --- a/example/react-component-tsx/README.md +++ b/example/react-component-tsx/README.md @@ -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 -``` \ No newline at end of file +npm run build +``` + +The build is minified and the filenames include the hashes. +Your app is ready to be deployed! \ No newline at end of file diff --git a/example/react-component-tsx/package.json b/example/react-component-tsx/package.json index c0a5365f..d524e9fe 100644 --- a/example/react-component-tsx/package.json +++ b/example/react-component-tsx/package.json @@ -1,22 +1,25 @@ { "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", @@ -24,21 +27,45 @@ }, "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%", diff --git a/example/react-component-tsx/public/index.html b/example/react-component-tsx/public/index.html index 40e7a6c9..a83fc7fa 100644 --- a/example/react-component-tsx/public/index.html +++ b/example/react-component-tsx/public/index.html @@ -2,14 +2,38 @@
- - - -