<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Parcel 打包示例(React HelloWorld)

        來源:懂視網 責編:小采 時間:2020-11-27 22:21:33
        文檔

        Parcel 打包示例(React HelloWorld)

        Parcel 打包示例(React HelloWorld):Parcel 打包特點 極速打包時間 Parcel 使用 worker 進程去啟用多核編譯。同時有文件系統緩存,即使在重啟構建后也能快速再編譯。 將你所有的資源打包 Parcel 具備開箱即用的對 JS, CSS, HTML, 文件 及更多的支持,而且不需要插件。 自動轉換 如若有需要,
        推薦度:
        導讀Parcel 打包示例(React HelloWorld):Parcel 打包特點 極速打包時間 Parcel 使用 worker 進程去啟用多核編譯。同時有文件系統緩存,即使在重啟構建后也能快速再編譯。 將你所有的資源打包 Parcel 具備開箱即用的對 JS, CSS, HTML, 文件 及更多的支持,而且不需要插件。 自動轉換 如若有需要,

        Parcel 打包特點

        極速打包時間

        Parcel 使用 worker 進程去啟用多核編譯。同時有文件系統緩存,即使在重啟構建后也能快速再編譯。

         將你所有的資源打包

        Parcel 具備開箱即用的對 JS, CSS, HTML, 文件 及更多的支持,而且不需要插件。

        自動轉換

        如若有需要,Babel, PostCSS, 和PostHTML甚至 node_modules 包會被用于自動轉換代碼.

        配置代碼分拆

        使用動態 import() 語法, Parcel 將你的輸出文件束(bundles)分拆,因此你只需要在初次加載時加載你所需要的代碼。

         熱模塊替換

        Parcel 無需配置,在開發環境的時候會自動在瀏覽器內隨著你的代碼更改而去更新模塊。

        友好的錯誤日志

        當遇到錯誤時,Parcel 會輸出 語法高亮的代碼片段,幫助你定位問題。

        使用 Parcel 打包的 React HelloWorld 應用。GitHub 地址: https://github.com/justjavac/parcel-example/tree/master/react-helloworld

        0. 新建目錄

        mkdir react-helloworld
        cd react-helloworld

        1. 初始化 npm

        yarn init -y

        npm init -y

        此時會創建要給 package.json 文件,文件內容:

        {
         "name": "parcel-example-react-helloworld",
         "version": "1.0.0",
         "description": "",
         "main": "index.js",
         "scripts": {
         "test": "echo \"Error: no test specified\" && exit 1"
         },
         "keywords": [],
         "author": "",
         "license": "ISC"
        }
        

        2. 添加 React

        yarn:

        yarn add react react-dom

        npm:

        npm install react react-dom --save

        package.json 文件內容:

         {
         "name": "parcel-example-react-helloworld",
         "version": "1.0.0",
         "description": "",
         "main": "index.js",
         "scripts": {
         "test": "echo \"Error: no test specified\" && exit 1"
         },
         "keywords": [],
         "author": "",
        - "license": "ISC"
        + "license": "ISC",
        + "dependencies": {
        + "react": "^16.2.0",
        + "react-dom": "^16.2.0"
        + }
         }
        

        3. 添加 Babel

        新建 .babelrc 文件

        touch .babelrc

        輸入內容:

        {
         "presets": ["react"]
        }

        添加 babel-preset-react:

        yarn:

        yarn add babel-preset-react -D

        npm:

        npm install babel-preset-react --D

        此時 package.json 文件內容:

         {
         "name": "parcel-example-react-helloworld",
         "version": "1.0.0",
         "description": "",
         "main": "index.js",
         "scripts": {
         "test": "echo \"Error: no test specified\" && exit 1"
         },
         "keywords": [],
         "author": "",
         "license": "ISC",
         "dependencies": {
         "react": "^16.2.0",
         "react-dom": "^16.2.0"
        - }
        + },
        + "devDependencies": {
        + "babel-preset-react": "^6.24.1"
        + }
         }
        

        5. 添加 Parcel

        yarn:

        yarn add parcel-bundler -D

        npm:

        npm install parcel-bundler --D

        此時 package.json 文件內容:

         {
         "name": "parcel-example-react-helloworld",
         "version": "1.0.0",
         "description": "",
         "main": "index.js",
         "scripts": {
         "test": "echo \"Error: no test specified\" && exit 1"
         },
         "keywords": [],
         "author": "",
         "license": "ISC",
         "dependencies": {
         "react": "^16.2.0",
         "react-dom": "^16.2.0"
         },
         "devDependencies": {
        - "babel-preset-react": "^6.24.1"
        + "babel-preset-react": "^6.24.1",
        + "parcel-bundler": "^1.0.3" 
         }
         }
        

        6. 新建 index.html 文件

        內容

        <html>
        <body>
         <div id="root"></div>
         <script src="./index.js"></script>
        </body>
        </html>
        

        7. 新建 index.js 文件

        import React from "react";
        import ReactDOM from "react-dom";
        const App = () => {
         return <h1>Hello World!</h1>;
        };
        
        ReactDOM.render(<App />, document.getElementById("root"));
        

        8. 添加打包命令

         {
         "name": "parcel-example-react-helloworld",
         "version": "1.0.0",
         "description": "",
         "main": "index.js",
         "scripts": {
        - "test": "echo \"Error: no test specified\" && exit 1"
        + "start": "parcel index.html"
         },
         "keywords": [],
         "author": "",
         "license": "ISC",
         "dependencies": {
         "react": "^16.2.0",
         "react-dom": "^16.2.0"
         },
         "devDependencies": {
         "babel-preset-react": "^6.24.1"
         "babel-preset-react": "^6.24.1",
         "parcel-bundler": "^1.0.3" 
         }
         }
        

        9. 完成

        運行

        yarn start

        npm start

        在瀏覽器中打開 http://localhost:1234

        打包過程會生產 .cache 和 dist 兩個目錄,如果是 git 工程,可以新建 .gitignore 文件忽略這兩個目錄:

        .cache
        dist
        node_modules

        GitHub 地址: https://github.com/justjavac/parcel-example/tree/master/react-helloworld

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Parcel 打包示例(React HelloWorld)

        Parcel 打包示例(React HelloWorld):Parcel 打包特點 極速打包時間 Parcel 使用 worker 進程去啟用多核編譯。同時有文件系統緩存,即使在重啟構建后也能快速再編譯。 將你所有的資源打包 Parcel 具備開箱即用的對 JS, CSS, HTML, 文件 及更多的支持,而且不需要插件。 自動轉換 如若有需要,
        推薦度:
        標簽: 打包 helloworld React
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 最新69国产成人精品免费视频动漫 | 成人亚洲国产精品久久| 91短视频免费在线观看| 亚洲理论片在线中文字幕| 久久久高清日本道免费观看| 亚洲日韩av无码| 久久精品视频免费| 久久亚洲sm情趣捆绑调教| 5g影院5g天天爽永久免费影院| 亚洲小视频在线观看| 91大神在线免费观看| 亚洲一区中文字幕在线电影网 | 337p日本欧洲亚洲大胆人人| 又粗又硬又黄又爽的免费视频 | 国产亚洲精品无码成人| 久久综合国产乱子伦精品免费| 永久免费观看的毛片的网站| 亚洲乱码无人区卡1卡2卡3| 在线观看免费精品国产| 一级做a免费视频观看网站| 亚洲av一综合av一区| 色片在线免费观看| 亚洲成年轻人电影网站www| 国产精品成人观看视频免费| 亚洲最大的成人网| 亚洲午夜爱爱香蕉片| 久99久精品免费视频热77| 亚洲av无码电影网| 亚洲国产主播精品极品网红| 日本免费在线中文字幕| 亚洲熟妇无码AV不卡在线播放| 亚洲美日韩Av中文字幕无码久久久妻妇| 中国国语毛片免费观看视频| 亚洲成综合人影院在院播放| 久久久久久AV无码免费网站下载| 亚洲人成电影在线观看青青| 精品国产亚洲一区二区在线观看| 少妇人妻偷人精品免费视频| 欧洲亚洲国产精华液| 亚洲成AV人在线播放无码| 好吊妞在线成人免费|