官术网_书友最值得收藏!

  • ReasonML Quick Start Guide
  • Raphael Rafatpanah Bruno Joseph D'mello
  • 204字
  • 2021-07-02 12:34:17

Setting up a ReasonReact project

To create a new ReasonReact project, run the following command:

bsb -init my-reason-react-app -theme react
cd my-reason-react-app

After opening our text editor, we see that a couple of things have changed. The package.json file lists the relevant React and webpack dependencies. Let's install them:

npm install

We also have the following webpack-related npm scripts:

"webpack": "webpack -w",
"webpack:production": "NODE_ENV=production webpack"

In bsconfig.json, we have a new field that turns on JSX for ReasonReact:

"reason": {
"react-jsx": 2
},

We have a simple webpack.config.js file:

const path = require("path");
const outputDir = path.join(__dirname, "build/");

const isProd = process.env.NODE_ENV === "production";

module.exports = {
entry: "./src/Index.bs.js",
mode: isProd ? "production" : "development",
output: {
path: outputDir,
publicPath: outputDir,
filename: "Index.js"
}
};

Note how the configured entry point is "./src/Index.bs.js", which makes sense since, by default, "in-source" is set to true in bsconfig.json. The rest is just normal webpack stuff.

To run this project, we need to run both bsb and webpack:

npm start

/* in another shell */
npm run webpack

/* in another shell */
php -S localhost:3000

Since the index.html file is located within the src directory, we visit http://localhost:3000/src to see the default application.

主站蜘蛛池模板: 绥中县| 子洲县| 儋州市| 南昌县| 郯城县| 榆中县| 苍南县| 惠东县| 宜兰县| 新安县| 安顺市| 沧州市| 兴化市| 瑞金市| 定陶县| 峨山| 遂平县| 永善县| 察隅县| 高阳县| 阿拉善左旗| 安乡县| 太白县| 渭源县| 顺义区| 镇宁| 湟源县| 达州市| 虹口区| 孝义市| 镇雄县| 张家港市| 车险| 永新县| 陈巴尔虎旗| 伊宁市| 龙川县| 永康市| 曲靖市| 定结县| 绵竹市|