从零开始实现一个react-01-环境配置parcel

123 阅读1分钟

1.环境配置:

依赖安装:

//项目根目录下执行
npm init -y

安装有依赖:
npm install parcel-bundler@1.12.3 --save-dev

npm install --save-dev babel-plugin-transform-react-jsx

npm i babel-core babel-preset-env --save-dev 

package.json:

因为上面安装了parcel的打包依赖,为了方便可以在scripts中添加 "start": "parcel index.html",然后通过npm start去安装

{
  "name": "react0",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "parcel index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.7.0",
    "parcel-bundler": "^1.12.3"
  },
  "dependencies": {},
  "description": ""
}

测试:

项目文件夹下创建创建一个index.html,以及index.js文件

终端运行npm start即可在端口http://localhost:1234中访问到页面。