React-webpack——開發一個react項目所需準備

來源:互聯網
上載者:User
npm init —產生package.json檔案

安裝依賴 npm install –save react npm install –save react-dom npm install –save-dev webpack npm install –save-dev webpack-dev-server npm install –save-dev babel-core npm install –save babel-polyfill npm install –save-dev babel-loader npm install –save-dev style-loader css-loader npm install –save-dev file-loader npm install –save babel-runtime npm install –save-dev babel-plugin-transform-runtime npm install –save-dev babel-preset-es2015 npm install –save-dev babel-preset-react npm install –save-dev babel-preset-stage-2 npm install –save webpack-cli’ npm install –save-dev node-sass//可以不加,相應的下面的配置中關於sass部分要刪去 npm install –save-dev sass-loader//可以不加 npm install redux react-redux //不知道redux的可以不加

開啟 package.json 然後添加下面的scripts:

“scripts”: {
“start”: “webpack-dev-server –hot –inline –colors –content-base ./build”,
“build”: “webpack –progress –colors”
}

配置webpack.config.js檔案

在根目錄下建立webpack.config.js檔案,輸入以下內容

```var webpack = require('webpack');module.exports = { entry: './src/app/index.js', output: {     path: __dirname + '/build',     filename: "bundle.js" }, module: {     rules: [{         test: /\.js$/,         exclude: /node_modules/,         loader: 'babel-loader',         query: {             plugins: ['transform-runtime'],             presets: ['es2015', 'react', 'stage-2']         }     },      {         test: /\.css$/,         use:['style-loader','css-loader']     },     {        test: /\.scss$/,        use: [            'css-loader',            'sass-loader'        ]    },    {        test: /\.(png|svg|jpg|gif|mp4)$/,        use: ['file-loader']    }    ] }};```

基本配置完成 接下來看看目錄
寫完代碼後運行npm start即可跑起來 剛接觸react的朋友可以去看官網的教程,兩句代碼就搞好一個腳手架,不需要自己配。對初學者還是很友好的。–>傳送門<–

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.