@variousjs/create 0.3.1 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@variousjs/create",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "VariousJS boilerplate",
5
5
  "bin": "bin/create.js",
6
6
  "publishConfig": {
@@ -33,10 +33,10 @@
33
33
  "@babel/preset-typescript": "^7.15.0",
34
34
  "@types/react": "^17.0.27",
35
35
  "@types/react-dom": "^17.0.9",
36
- "@types/react-router-dom": "^5.3.1",
36
+ "@types/react-router-dom": "^5.3.3",
37
37
  "@typescript-eslint/eslint-plugin": "^4.31.2",
38
38
  "@typescript-eslint/parser": "^4.31.2",
39
- "@variousjs/various": "^0.4.0",
39
+ "@variousjs/various": "^0.6.0",
40
40
  "babel-loader": "^8.2.2",
41
41
  "css-loader": "^6.3.0",
42
42
  "eslint": "^7.32.0",
@@ -51,6 +51,6 @@
51
51
  "typescript": "^4.4.3",
52
52
  "webpack": "^5.54.0",
53
53
  "webpack-cli": "^4.8.0",
54
- "webpack-dev-server": "^4.3.0"
54
+ "webpack-dev-server": "^4.7.3"
55
55
  }
56
56
  }
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "variousjs",
3
+ "version": "0.1.0",
4
+ "description": "VariousJS boilerplate",
5
+ "scripts": {
6
+ "lint": "tsc --noemit && eslint . --ext .ts,.tsx,.js",
7
+ "start": "webpack --progress --config ./webpack/component.js & webpack serve --config ./webpack/entry.js --progress",
8
+ "build": "webpack --progress --config ./webpack/base.js"
9
+ },
10
+ "author": "LoeiFy <LoeiFy@gmail.com>",
11
+ "license": "MIT",
12
+ "devDependencies": {
13
+ "@babel/core": "^7.15.5",
14
+ "@babel/preset-env": "^7.15.6",
15
+ "@babel/preset-react": "^7.14.5",
16
+ "@babel/preset-typescript": "^7.15.0",
17
+ "@types/react": "^17.0.27",
18
+ "@types/react-dom": "^17.0.9",
19
+ "@types/react-router-dom": "^5.3.3",
20
+ "@typescript-eslint/eslint-plugin": "^4.31.2",
21
+ "@typescript-eslint/parser": "^4.31.2",
22
+ "@variousjs/various": "^0.6.0",
23
+ "babel-loader": "^8.2.2",
24
+ "css-loader": "^6.3.0",
25
+ "eslint": "^7.32.0",
26
+ "eslint-import-resolver-typescript": "^2.5.0",
27
+ "eslint-plugin-import": "^2.24.2",
28
+ "eslint-plugin-jsx-a11y": "^6.4.1",
29
+ "eslint-plugin-react": "^7.26.0",
30
+ "eslint-plugin-react-hooks": "^4.2.0",
31
+ "less": "^4.1.1",
32
+ "less-loader": "^10.0.1",
33
+ "style-loader": "^3.3.0",
34
+ "typescript": "^4.4.3",
35
+ "webpack": "^5.54.0",
36
+ "webpack-cli": "^4.8.0",
37
+ "webpack-dev-server": "^4.7.3"
38
+ },
39
+ "private": true
40
+ }
@@ -1,10 +1,11 @@
1
1
  import React, { FC } from 'react'
2
2
  import { ComponentProps } from '@variousjs/various'
3
+ import { useParams } from 'react-router-dom'
3
4
  import { Card, Button, message } from 'antd'
4
5
  import csses from './card.less'
5
6
 
6
7
  const H: FC<ComponentProps> & { getName: (e: string) => any } = (props) => {
7
- const id = props.$router?.match.params.id
8
+ const { id } = useParams<{ id: string }>()
8
9
 
9
10
  return (
10
11
  <div className={csses.container}>
@@ -0,0 +1,54 @@
1
+ import React, { FC, useState, useEffect } from 'react'
2
+ import { ComponentProps } from '@variousjs/various'
3
+ import { useLocation, useHistory } from 'react-router-dom'
4
+ import { Radio, Badge, Button } from 'antd'
5
+ import { Config, Store } from '../types'
6
+
7
+ const H: FC<ComponentProps<Store, Config>> = (props) => {
8
+ const { pathname } = useLocation()
9
+ const history = useHistory()
10
+ const [path, setPath] = useState('')
11
+
12
+ useEffect(() => {
13
+ setPath(pathname)
14
+ }, [])
15
+
16
+ const onRouterChange = (e: any) => {
17
+ history.push(e.target.value)
18
+ setPath(e.target.value)
19
+ }
20
+
21
+ return (
22
+ <>
23
+ <Radio.Group
24
+ size="large"
25
+ value={path}
26
+ onChange={onRouterChange}
27
+ buttonStyle="solid"
28
+ >
29
+ {
30
+ props.$config.links.map(({ path, name }) => (
31
+ <Radio.Button key={path} value={path}>
32
+ {name}
33
+ </Radio.Button>
34
+ ))
35
+ }
36
+ </Radio.Group>
37
+ <div>
38
+ Store:
39
+ <Badge
40
+ style={{ marginLeft: 10 }}
41
+ count={props.$store.user.name}
42
+ />
43
+ <Button
44
+ style={{ marginLeft: 10 }}
45
+ onClick={() => props.$dispatch('card', 'getName', 'Card')}
46
+ >
47
+ Card Name
48
+ </Button>
49
+ </div>
50
+ </>
51
+ )
52
+ }
53
+
54
+ export default H
@@ -1,60 +1,20 @@
1
1
  import React, { Component, ComponentType } from 'react'
2
- import { ContainerProps, Router, Route } from '@variousjs/various'
3
- import { Radio, Badge, Button } from 'antd'
4
- import { Store, Config } from '../types'
2
+ import { ContainerProps } from '@variousjs/various'
3
+ import { HashRouter as Router, Route } from 'react-router-dom'
4
+ import { Config } from '../types'
5
5
  import csses from './entry.less'
6
6
 
7
- class Container extends Component<ContainerProps<Store, Config>> {
8
- state = {
9
- path: '/'
10
- }
11
-
12
- onRouterChange = (e: any) => {
13
- this.props.$router.history.push(e.target.value)
14
- this.setState({ path: e.target.value })
15
- }
16
-
17
- componentDidMount() {
18
- this.setState({ path: this.props.$router.location.pathname })
19
- }
20
-
7
+ class Container extends Component<ContainerProps<Config>> {
21
8
  render() {
22
- const { $component, $config, $store } = this.props
9
+ const { $component, $config } = this.props
10
+ const Top = $component('top')
23
11
 
24
12
  return (
25
13
  <div className={csses.container}>
26
- <div className={csses.top}>
27
- <Radio.Group
28
- size="large"
29
- value={this.state.path}
30
- onChange={this.onRouterChange}
31
- buttonStyle="solid"
32
- >
33
- {
34
- $config.links.map(({ path, name }) => (
35
- <Radio.Button key={path} value={path}>
36
- {name}
37
- </Radio.Button>
38
- ))
39
- }
40
- </Radio.Group>
41
-
42
- <div>
43
- Store:
44
- <Badge
45
- style={{ marginLeft: 10 }}
46
- count={$store.user.name}
47
- />
48
- <Button
49
- style={{ marginLeft: 10 }}
50
- onClick={() => this.props.$dispatch('card', 'getName', 'Card')}
51
- >
52
- Card Name
53
- </Button>
54
- </div>
55
- </div>
56
-
57
14
  <Router>
15
+ <div className={csses.top}>
16
+ <Top />
17
+ </div>
58
18
  {
59
19
  $config.pages.map(({ path, components }) => {
60
20
  const cs = () => components.map((name) => {
package/webpack/base.js CHANGED
@@ -8,6 +8,7 @@ const config = {
8
8
  // 组件入口定义
9
9
  card: path.join(__dirname, '../src/components/card.tsx'),
10
10
  next: path.join(__dirname, '../src/components/next.tsx'),
11
+ top: path.join(__dirname, '../src/components/top.tsx'),
11
12
  },
12
13
  output: {
13
14
  path: path.resolve(__dirname, '../demo/dist'),
@@ -26,6 +27,10 @@ const config = {
26
27
  root: 'ReactDOM',
27
28
  amd: 'react-dom',
28
29
  },
30
+ 'react-router-dom': {
31
+ root: 'ReactRouterDOM',
32
+ amd: 'react-router-dom',
33
+ },
29
34
  '@variousjs/various': {
30
35
  root: 'various',
31
36
  amd: '@variousjs/various',
@@ -47,7 +52,6 @@ const config = {
47
52
  allowedHosts: 'all',
48
53
  port: 2333,
49
54
  host: '0.0.0.0',
50
- https: true,
51
55
  static: {
52
56
  directory: path.join(__dirname, '../demo'),
53
57
  },