创建react项目 Linux,idea2018 快速搭建react项目指南
react与angular和vue是截止2018年为止主流的前端框架。对于一些新手来说,想快速入门react,应该是搭建一个react最初的模板项目,然后在项目中添加一些自己喜欢的组件作为练手。。今天本人用ideaIntelliJ IDEA,快速搭建react项目。首先需要准备如下几个版本 ,项目名称为dragtest,本人想用这个测试react中的dragact组件的使用,这个草鸡吊!!
ideta版本:
2018.1.4 (Ultimate Edition)
Linux 4.15.0-23-generic
nodejs: 版本 v8.10.0,是本地js运行编译环境
npm: 版本3.5.2,用来管理react项目的快速安装环境,类似于python中的 pip 可以安装指定包
npm执行命令在路径:/usr/share/npm中,在项目启动的时候需要制定该路径
creat-react-app : 由npm isntall 安装生成的,为什么单独列出这个呢?这个是关键,因为要创建react,最普通的方式
就是通过命令 create-react-app projectname 生成 名为projectname的项目,那么idea为了方便大家快速搭建,需要用到
create-react-app中的index.js文件用来创建react应用,所以不清楚自己的create-react-app包在哪里的同学可以看看如下图
找的时候要特别小心, 直接通过whereis查找的是linux引用文件,并非真实的包存在的地方,用idea创建需要引用真实的地方
其实有个更好的命令
zhangll 23:04:09 ~ $ npm root -g /usr/local/lib/node_modules
构建app
第一步:进入
第二步,配置文件
注意:这里的script & version 不用写,除非你知道create-react-app的版本号
成功搭建:
这里需要用户耐心等待喽:
/usr/bin/node /usr/local/lib/node_modules/create-react-app/index.js dragtest
Creating a new React app in /tmp/1530428561698-0/dragtest.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...
> uglifyjs-webpack-plugin@0.4.6 postinstall /tmp/1530428561698-0/dragtest/node_modules/uglifyjs-webpack-plugin
> node lib/post_install.js
...........
Success! Created dragtest at /tmp/1530428561698-0/dragtest Inside that directory, you can run several commands:
npm start
Starts the development server.
npm run build
Bundles the app into static files for production.
npm test
Starts the test runner.
npm run eject
Removes this tool and copies build dependencies, configuration files
and scripts into the app directory. If you do this, you can’t go back!
We suggest that you begin by typing:
cd dragtest
npm start
Happy hacking!
Done
这里的意思是nodejs在tmp文件夹下生成一个react模板,生成好以后idea会在项目中引入这个模板
最终:
可以看到npm的强大之处,你只要双击 start 就会弹出如下图
选中好npm的包管理脚本位置之后会出现 3.5.2版本的标记
当然还有一种快捷方式就是在idea中配置一个链接到该位置的变量:方法如下
打开 File>Settings 配置,然后在左上角搜索 npm
start。。。
参考 nvm、npm、nodejs关系
https://www.cnblogs.com/qqpw/p/6597295.html
idea官方建立文档
http://www.jetbrains.com/help/idea/react.html
github教程
https://github.com/facebook/create-react-app
测试之后发现 start无法运行
/usr/bin/node /usr/share/npm/bin/npm-cli.js run start --scripts-prepend-node-path=auto
> dragtest@0.1.0 start /home/zhangll/tomcat/apache-tomcat-7.0.69/webapps/dragtest
> react-scripts start
module.js:549
throw err;
^
Error: Cannot find module '../scripts/start' at Function.Module._resolveFilename (module.js:547:15)
at Function.resolve (internal/module.js:18:19)
at Object. ( /home/zhangll/tomcat/apache-tomcat-7.0.69/webapps/dragtest/node_modules/.bin/react-scripts :28:25)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
npm ERR! Linux 4.15.0-23-generic
npm ERR! argv "/usr/bin/node" "/usr/share/npm/bin/npm-cli.js" "run" "start" "--scripts-prepend-node-path=auto"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! dragtest@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the dragtest@0.1.0 start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the dragtest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs dragtest
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls dragtest
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/zhangll/tomcat/apache-tomcat-7.0.69/webapps/dragtest/npm-debug.log
Process finished with exit code 1
其实之前已经发现 idea 会在/tmp/1530428561698-0/中生成一个文件,然后最后以某种方式copy到原文件,导致相对路径出错
解决方案是把/tmp/1530428561698-0/中的model包全部copy一份到idea目录下
cp -r /tmp/1530428561698-0/dragtest/node_modules /home/zhangll/tomcat/apache-tomcat-7.0.69/webapps/dragtest/
方案解决。。。。。这个应该是idea中的一个bug。。。。希望idea能修复这个bug
创建react项目 Linux,idea2018 快速搭建react项目指南相关推荐
- linux下测试个人主页,一键建站集成软件包,Linux上快速搭建测试个人网站
原标题:一键建站集成软件包,Linux上快速搭建测试个人网站 来自:Linux迷 https://www.linuxmi.com/ubuntu-20-0-linux-xampp.html 在Ubunt ...
- 快速搭建Springboot项目的两种方式!!
大家好,我是雄雄,欢迎关注微信公众号[雄雄的小课堂]. 前言 Springboot的特点就是简单.快速和方便,使用idea不到一分钟就可以快速搭建springboot项目,并且,在这里,你不用写spr ...
- linux的建站安装包,一键建站集成软件包,Linux上快速搭建测试个人网站
原标题:一键建站集成软件包,Linux上快速搭建测试个人网站 来自:Linux迷 https://www.linuxmi.com/ubuntu-20-0-linux-xampp.html 在Ubunt ...
- linux怎样搭建DNS服务器,Linux下快速搭建DNS服务器
摘要 腾兴网为您分享:Linux下快速搭建DNS服务器,作业盒子,优学堂,湘税社保,悟空识字等软件知识,以及初中英语app,新榜编辑器,神界原罪2,少儿英语点读app,minecraft皮肤编辑器, ...
- linux开发 stc_在Linux上快速搭建8051开发环境
在Linux上快速搭建8051开发环境(2018-7-2) 0. 写在开始之前 实验操作系统环境: Ubuntu 16.04 编译器: sdcc SDCC - Small Device C Compi ...
- 快速搭建SSM项目【最全教程】~令狐小哥版
快速搭建SSM项目[最全教程]~令狐小哥版 文章目录 快速搭建SSM项目[最全教程]~令狐小哥版 一.创建项目 二.集成spring依赖 三.创建applicationContext.xml文件 四. ...
- 利用宝塔面板的Python项目管理器快速搭建CuteOne项目
前言:一般的Linux系统默认安装了python2.x,当运行需要python3.x的项目几乎都会报错,要更换python的版本挺麻烦的,可能会因为一个小步骤没搞好,缺少库之类的,或者没配置好影响py ...
- linux进行校时ntp,Linux下快速搭建ntp时间同步服务器
Linux下快速搭建ntp时间同步服务器 背景: 服务器多了,时间是否一致以及是否准备就显得格外重要,虽然这个问题总是被忽略,但是统一时间是很有必要的,因为时间问题导致服务出现问题也是司空见惯,本文简 ...
- 快速搭建react项目骨架(按需加载、redux、axios、项目级目录等等)
一.前言 最近整理了一下项目骨架,顺便自定义了一个脚手架,方便日后使用.我会从头开始,步骤一步步写明白,如果还有不清楚的可以评论区留言.先大致介绍一下这个骨架,我们采用 create-react-ap ...
最新文章
- There's no Qt version assigned to this project for platform Win32/Win64
- Anaconda3 离线安装和配置 Django-3.2.7 使用 MySQL-5.7 数据库
- 【青少年编程】黄羽恒:Python
- Kamailio v4.4.6 发布,开源 SIP 服务器
- 功率谱 魏凤英统计程序_频谱、能量谱、功率谱、功率谱估计
- windows下配置mysql主从复制_Windows下MySQL主从复制的配置方法
- winform执行oracle语句,C#中的Winform应用程序连接远程Oracle数据库的配置文件及SQL语句的写法...
- Julia : global、local 以及 作用域问题
- OpenCV里IplImage数据结构中width和widthStep极易出错的问题
- POI和EasyExcel操作Excel
- 店群怎么玩?2020最新玩法介绍 胖哥给大家分享干货
- App开发者必备的运营、原型、UI设计工具整理
- HTML5自造字,电脑中的造字程序怎么用啊怎么造字
- practice是什么意思_practice是什么意思
- 深入浅出数据分析读书笔记
- C语言贪吃蛇大作战实训心得,在《贪吃蛇大作战》中感悟一些道理
- 某品牌服务器raid5阵列删除数据恢复过程分析
- Python语言更适合低代码开发平台
- Windows系统下QT+OpenCasCAD仿真开发
- 视频录制30帧还是60帧清晰?