Git Product home page Git Product logo

react-demo's Introduction

1.在当前目录下快速创建create-react-app ts项目

yarn create react-app . --template typescript
yarn add antd
yarn add @craco/craco
yarn add craco-antd
yarn add craco-less
yarn add nodemon
yarn add react-router-dom
yarn add redux
yarn add react-redux
yarn add @reduxjs/toolkit
yarn add http-proxy-middleware -D

创建craco.config.js配置文件:

const CracoAntDesignPlugin = require('craco-antd');
const CracoLessPlugin = require('craco-less')
const {loaderByName} = require("@craco/craco");
process.env.BROWSER = "none"
module.exports = {
    plugins: [
        {
            plugin: CracoAntDesignPlugin,
            options: {
                customizeTheme: {
                    '@primary-color': '#3ace23',
                    '@layout-header-background':'#24292f'

                },
            },
        },
        {
            plugin: CracoLessPlugin,
            options: {
                modifyLessRule(lessRule, context) {
                    // You have to exclude these file suffixes first,
                    // if you want to modify the less module's suffix
                    lessRule.exclude = /\.module\.less$/
                    return lessRule
                },
                modifyLessModuleRule(lessModuleRule, context) {
                    // Configure the file suffix
                    lessModuleRule.test = /\.module\.less$/

                    // Configure the generated local ident name.
                    const cssLoader = lessModuleRule.use.find(loaderByName('css-loader'))
                    cssLoader.options.modules = {
                        localIdentName: '[local]_[hash:base64:5]'
                    }

                    return lessModuleRule
                },

                lessLoaderOptions: {
                    lessOptions: {
                        // modifyVars: {"@primary-color": "#1DA57A"},
                        javascriptEnabled: true
                    }
                }

                // modifyVars: {
                //     'primary-color': '#1DA57A',
                //     'link-color': '#1DA57A',
                //     'border-radius-base': '2px',
                // },
            }
        }
    ],
};

修改package.json:

{
  "scripts": {
    "start": "nodemon -w craco.config.js  --exec \"craco start\"",
    "build": "craco build",
    "test": "craco test"
  },  
}  

设置代理src/setupProxy.js

const {createProxyMiddleware} = require("http-proxy-middleware");
module.exports = function (app) {
    app.use(
        "/api",
        createProxyMiddleware({
            target: "服务器名:端口",
            changeOrigin: true,
            pathRewrite: {'^/api': ''}

        })
    )

};

修改src/react-app-env.d.ts:

/// <reference types="react-scripts" />
// 配置支持模块化less
declare module '*.module.less' {
    const classes: {
        readonly [key: string]: string
    }
    export default classes
    declare module '*.less'
}

2.启动项目

yarn start
yarn build
yarn eject

react-demo's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.