react系列学习(1)---creat-react-app搭建项目

204 阅读1分钟

一、create-react-app脚手架的使用

    npm i -g create-react-app
    create-react-app my-app
    cd my-app
    npm run eject   // 将webpack配置文件暴露出来
    npm run start

搭建的项目目录

image.png

运行

    npm run start

image.png

二、使用serve搭建服务器

1. 打包

    npm run build

2. 安装serve

    npm i -g serve

3. 托管build

    serve -s build

启动成功

image.png

三、APP.js中 rel="noopener noreferrer" 安全保护

image.png

去掉会报错

image.png

四、打开开发模式下的source-map断点调试

1. 默认开发模式和生产模式都没有开放source-map

image.png

image.png

2.打开后效果

devtool: isEnvProduction
      ? shouldUseSourceMap            // 改为true可以打开生产环境
        ? 'source-map'                // eval-source-map 这里是打开生产环境的调试
        : false
      : isEnvDevelopment && 'eval-source-map',   // eval-source-map 这里是打开测试环境的调试

image.png

npm run start // 重启

image.png