/ts-react-webpack

a starter-template with typescript, react, mobx and webpack...

Primary LanguageTypeScript

typescript + react + webpack starter

this is a simple starter looks like:

setup

$ npm i

build for development

$ npm run dev

build for production

$ npm run qa/prod

characteristics/packages

functional example

mobx-react-router

import * as React from 'react'
import { inject, observer } from 'mobx-react'
import { Button } from 'antd'

import * as styles from './index.scss'

interface Props {
    routerStore?: RouterStore;
}

function Test(props: Props) {
    const { routerStore } = props
    const gotoHome = () => {
        routerStore.push('/')
    }
    return (
        <div className={styles.login}>
            Login!!!
            <div className={styles.btnGroup}>
                <Button type="primary" onClick={gotoHome}>
                    go to page index directly
                </Button>
            </div>
        </div>
    )
}

export default inject('routerStore')(observer(Login))

live example

async to load component

import * as React from 'react'
import { hot } from 'react-hot-loader'
import Loadable from 'react-loadable'
import { HashRouter as Router, Switch, Route } from 'react-router-dom'

import PageLoading from '@components/PageLoading'

const Test = Loadable({
    loader: () => import(/* webpackChunkName: "test" */ './Test'),
    loading: PageLoading
})

const AppRouter = () => (
    <Router>
        <Switch>
            <Route exact path="/test" component={Test} />
        </Switch>
    </Router>
)

export default hot(module)(AppRouter)

live example

how to deploy with nginx

server {
       listen       9993;
       server_name  localhost:9993;

       location / {
             root   ~/Documents/react/ts-react-webpack4/dist/qa/;
             index  index.html index.htm;
       }
 }

the scaffold

steamer-react-redux-ts