Skip to content

Commit 64991f3

Browse files
committed
init
0 parents  commit 64991f3

21 files changed

+7435
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["taro"],
3+
"rules": {
4+
"react/jsx-filename-extension": [1, { "extensions": [".js"] }]
5+
},
6+
"parser": "babel-eslint"
7+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
.temp/
3+
node_modules/

config/dev.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
env: {
3+
NODE_ENV: '"development"'
4+
},
5+
defineConstants: {
6+
},
7+
weapp: {},
8+
h5: {}
9+
}

config/index.js

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const config = {
2+
projectName: 'v2ex',
3+
date: '2018-8-3',
4+
designWidth: 750,
5+
sourceRoot: 'src',
6+
outputRoot: 'dist',
7+
plugins: {
8+
babel: {
9+
sourceMap: true,
10+
presets: [
11+
'env'
12+
],
13+
plugins: [
14+
'transform-class-properties',
15+
'transform-decorators-legacy',
16+
'transform-object-rest-spread'
17+
]
18+
},
19+
typescript: {
20+
compilerOptions: {
21+
allowSyntheticDefaultImports: true,
22+
baseUrl: '.',
23+
declaration: false,
24+
experimentalDecorators: true,
25+
jsx: 'react',
26+
jsxFactory: 'Nerv.createElement',
27+
module: 'commonjs',
28+
moduleResolution: 'node',
29+
noImplicitAny: false,
30+
noUnusedLocals: true,
31+
outDir: './dist/',
32+
preserveConstEnums: true,
33+
removeComments: false,
34+
rootDir: '.',
35+
sourceMap: true,
36+
strictNullChecks: true,
37+
target: 'es6'
38+
},
39+
include: [
40+
'src/**/*'
41+
],
42+
exclude: [
43+
'node_modules'
44+
],
45+
compileOnSave: false
46+
}
47+
},
48+
defineConstants: {
49+
},
50+
weapp: {
51+
52+
},
53+
h5: {
54+
publicPath: '/',
55+
staticDirectory: 'static',
56+
module: {
57+
postcss: {
58+
autoprefixer: {
59+
enable: true
60+
}
61+
}
62+
}
63+
}
64+
}
65+
66+
module.exports = function (merge) {
67+
if (process.env.NODE_ENV === 'development') {
68+
return merge({}, config, require('./dev'))
69+
}
70+
return merge({}, config, require('./prod'))
71+
}

config/prod.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
env: {
3+
NODE_ENV: '"production"'
4+
},
5+
defineConstants: {
6+
},
7+
weapp: {},
8+
h5: {}
9+
}

package.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "v2ex",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "v2ex-taro",
6+
"main": "index.js",
7+
"scripts": {
8+
"build:weapp": "taro build --type weapp",
9+
"build:h5": "taro build --type h5",
10+
"dev:weapp": "npm run build:weapp -- --watch",
11+
"dev:h5": "npm run build:h5 -- --watch",
12+
"test": "eslint src/ --ext .tsx"
13+
},
14+
"author": "",
15+
"license": "MIT",
16+
"dependencies": {
17+
"@tarojs/async-await": "^1.0.0-beta.6",
18+
"@tarojs/components": "^1.0.0-beta.6",
19+
"@tarojs/redux": "^1.0.0-beta.6",
20+
"@tarojs/redux-h5": "^1.0.0-beta.6",
21+
"@tarojs/router": "^1.0.0-beta.6",
22+
"@tarojs/taro": "^1.0.0-beta.6",
23+
"@tarojs/taro-h5": "^1.0.0-beta.6",
24+
"@tarojs/taro-weapp": "^1.0.0-beta.6",
25+
"nervjs": "^1.3.0",
26+
"redux": "^4.0.0",
27+
"redux-actions": "^2.6.1",
28+
"redux-logger": "^3.0.6",
29+
"redux-thunk": "^2.3.0"
30+
},
31+
"devDependencies": {
32+
"@tarojs/cli": "^1.0.0-beta.6",
33+
"@tarojs/plugin-babel": "^1.0.0-beta.6",
34+
"@tarojs/plugin-csso": "^1.0.0-beta.6",
35+
"@tarojs/plugin-typescript": "^1.0.0-beta.6",
36+
"@tarojs/plugin-uglifyjs": "^1.0.0-beta.6",
37+
"@tarojs/webpack-runner": "^1.0.0-beta.6",
38+
"@types/redux-actions": "^2.3.0",
39+
"babel-eslint": "^8.2.3",
40+
"babel-plugin-transform-class-properties": "^6.24.1",
41+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
42+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
43+
"babel-preset-env": "^1.6.1",
44+
"eslint": "^5.2.0",
45+
"eslint-config-taro": "1.0.0-beta.6",
46+
"eslint-plugin-import": "^2.12.0",
47+
"eslint-plugin-react": "^7.8.2",
48+
"eslint-plugin-taro": "1.0.0-beta.6",
49+
"tslint": "^5.11.0",
50+
"tslint-config-standard": "^7.1.0",
51+
"tslint-react": "^3.6.0",
52+
"typescript": "^2.9.2",
53+
"typescript-eslint-parser": "^17.0.1"
54+
}
55+
}

project.config.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"miniprogramRoot": "./dist",
3+
"projectname": "v2ex",
4+
"description": "v2ex-taro",
5+
"appid": "touristappid",
6+
"setting": {
7+
"urlCheck": true,
8+
"es6": false,
9+
"postcss": false,
10+
"minified": false
11+
},
12+
"compileType": "miniprogram"
13+
}

src/actions/counter.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
ADD,
3+
MINUS
4+
} from '../constants/counter'
5+
6+
export const add = () => {
7+
return {
8+
type: ADD
9+
}
10+
}
11+
export const minus = () => {
12+
return {
13+
type: MINUS
14+
}
15+
}
16+
17+
// 异步的action
18+
export function asyncAdd () {
19+
return dispatch => {
20+
setTimeout(() => {
21+
dispatch(add())
22+
}, 2000)
23+
}
24+
}

src/app.css

Whitespace-only changes.

src/app.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Taro, { Component } from '@tarojs/taro'
2+
import '@tarojs/async-await'
3+
import { Provider } from '@tarojs/redux'
4+
5+
import Index from './pages/index'
6+
7+
import configStore from './store'
8+
9+
import './app.css'
10+
11+
const store = configStore()
12+
13+
class App extends Component {
14+
config = {
15+
pages: [
16+
'pages/index/index'
17+
],
18+
window: {
19+
backgroundTextStyle: 'light',
20+
navigationBarBackgroundColor: '#fff',
21+
navigationBarTitleText: 'WeChat',
22+
navigationBarTextStyle: 'black'
23+
}
24+
}
25+
26+
render () {
27+
return (
28+
<Provider store={store}>
29+
<Index />
30+
</Provider>
31+
)
32+
}
33+
}
34+
35+
Taro.render(<App />, document.getElementById('app'))

src/constants/counter.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const ADD = 'ADD'
2+
export const MINUS = 'MINUS'

src/index.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
5+
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
6+
<meta name="apple-mobile-web-app-capable" content="yes">
7+
<meta name="apple-touch-fullscreen" content="yes">
8+
<meta name="format-detection" content="telephone=no,address=no">
9+
<meta name="apple-mobile-web-app-status-bar-style" content="white">
10+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
11+
<title>Taro</title>
12+
<script>
13+
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
14+
</script>
15+
</head>
16+
<body>
17+
<div id="app"></div>
18+
</body>
19+
</html>

src/pages/index/index.css

Whitespace-only changes.

src/pages/index/index.tsx

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Taro, { Component } from '@tarojs/taro'
2+
import { View, Button } from '@tarojs/components'
3+
import { connect } from '@tarojs/redux'
4+
5+
import { add, minus, asyncAdd } from '../../actions/counter'
6+
7+
import './index.css'
8+
9+
@connect(({ counter }) => ({
10+
counter
11+
}), (dispatch) => ({
12+
add () {
13+
dispatch(add())
14+
},
15+
dec () {
16+
dispatch(minus())
17+
},
18+
asyncAdd () {
19+
dispatch(asyncAdd())
20+
}
21+
}))
22+
class Index extends Component {
23+
config = {
24+
navigationBarTitleText: '首页'
25+
}
26+
27+
render () {
28+
return (
29+
<View className='index'>
30+
<Button className='add_btn' onClick={this.props.add}>+</Button>
31+
<Button className='dec_btn' onClick={this.props.dec}>-</Button>
32+
<Button className='dec_btn' onClick={this.props.asyncAdd}>async</Button>
33+
<View>{this.props.counter.num}</View>
34+
<View>Hello, World</View>
35+
</View>
36+
)
37+
}
38+
}
39+
40+
export default Index

src/reducers/counter.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ADD, MINUS } from '../constants/counter'
2+
3+
const INITIAL_STATE = {
4+
num: 0
5+
}
6+
7+
export default function counter (state = INITIAL_STATE, action) {
8+
switch (action.type) {
9+
case ADD:
10+
return {
11+
...state,
12+
num: state.num + 1
13+
}
14+
case MINUS:
15+
return {
16+
...state,
17+
num: state.num - 1
18+
}
19+
default:
20+
return state
21+
}
22+
}

src/reducers/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from 'redux'
2+
import counter from './counter'
3+
4+
export default combineReducers({
5+
counter
6+
})

src/store/index.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createStore, applyMiddleware } from 'redux'
2+
import thunkMiddleware from 'redux-thunk'
3+
import rootReducer from '../reducers'
4+
5+
const middlewares = [
6+
thunkMiddleware
7+
]
8+
9+
export default function configStore () {
10+
const store = createStore(rootReducer, applyMiddleware(...middlewares))
11+
return store
12+
}

tsconfig.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2017",
4+
"module": "commonjs",
5+
"removeComments": false,
6+
"preserveConstEnums": true,
7+
"moduleResolution": "node",
8+
"experimentalDecorators": true,
9+
"noImplicitAny": false,
10+
"allowSyntheticDefaultImports": true,
11+
"outDir": "lib",
12+
"noUnusedParameters": true,
13+
"noUnusedLocals": false,
14+
"strictNullChecks": true,
15+
"sourceMap": true,
16+
"baseUrl": ".",
17+
"rootDir": ".",
18+
"jsx": "preserve",
19+
"jsxFactory": "Taro.createElement"
20+
},
21+
"exclude": [
22+
"__tests__",
23+
"node_modules",
24+
"dist",
25+
"tests",
26+
"jest",
27+
"lib",
28+
"**/*.test.ts",
29+
"**/*.spec.ts"
30+
],
31+
"compileOnSave": false
32+
}

tslint.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["tslint-config-standard", "tslint-react"]
3+
}

0 commit comments

Comments
 (0)