Setup Laravel 5.4 to use React

前端 未结 2 815
死守一世寂寞
死守一世寂寞 2021-02-05 10:50

I am not new to Laravel but am new to JavaScript frameworks.

I want to use React in a laravel build but cannot find any information on how to do this.

I have Lar

2条回答
  •  醉酒成梦
    2021-02-05 11:34

    According to the docs, React support is built in to Mix:

    Mix can automatically install the Babel plug-ins necessary for React support. To get started, replace your mix.js() call with mix.react():

    mix.react('resources/assets/js/app.jsx', 'public/js');
    

    Behind the scenes, Mix will download and include the appropriate babel-preset-react Babel plug-in.

    I'm not 100% sure whether or not this'll automatically include React in your output bundle - my guess would be no (in which case you'll have to use a normal mix.js() call to pull it in).

提交回复
热议问题