CRACO 快速使用

Getting Started | CRACO
craco 是专门由于 cra 配置的重写,扩展配置 cra (webpack)。

  1. 安装依赖

    npm i -D @craco/craco
    
  2. 根目录下创建 craco.config.js 和配置 configure:

      my-app
      ├── node_modules
    + ├── craco.config.js
      └── package.json
    

    craco.config.js

    module.exports = {
        devServer: {
            proxy: {
                '/api': {
                    target: 'http://localhost:3000',
                    changeOrigin: true,
                }
            }
        }
    }
    
  3. 脚本更改:

    package.json

    "scripts": {
    -  "start": "react-scripts start"
    +  "start": "craco start"
    -  "build": "react-scripts build"
    +  "build": "craco build"
    -  "test": "react-scripts test"
    +  "test": "craco test"
    }
    

你可能感兴趣的:(React,及其周边生态,前端,javascript)