[英]Why we need the --scripts-version command line option for create-react-app?
[英]create-react-app: using --scripts-version and --typescript
我學習將React與Typescript一起使用。 在手冊中,我看到它使用--scripts-version
參數創建新應用程序:
create-react-app my-app --scripts-version=react-scripts-ts
我也看到create-react-app
具有--typescript
選項。 所以,我可以這樣寫:
create-react-app my-app --typescript
這些基於React的應用程序創建方法有什么區別? 指定這兩個參數是否有意義? 即
create-react-app my-app --typescript --scripts-version=react-scripts-ts
兩者都沒有意義:
create-react-app my-app --typescript --scripts-version=react-scripts-ts
react-scripts-ts
已棄用 :
create-react-app現在本地支持打字稿-請閱讀將打字稿添加到現有項目的指南。
正如create-react-app
文檔所述,
要使用TypeScript啟動新的Create React App項目,可以運行:
npx create-react-app my-app --typescript # or yarn create-react-app my-app --typescript
不同之處在於react-scripts-ts
使用TypeScript而不是Babel,而create-react-app
使用Babel和TypeScript插件。 這導致一些限制 :
不支持名稱空間。 解決方法:改為使用文件導出,或改為使用模塊{}語法。
不支持const枚舉,因為它們需要類型信息才能進行編譯。 解決方法:刪除const,使其在運行時可用。
不支持export =和import =,因為它們不能編譯為ES.next。 解決方法:轉換為使用導出默認值和導出const,然后從“ z”導入x,{y}。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.