2017-04-01 55 views

回答

1

您需要安裝一些依賴於配置引導在反應

首先安裝以下loadersdependencies

npm install react react-dom bootstrap babel-preset-react --save 

npm install webpack css-loader style-loader file-loader url-loader babel-core babel-loader babel-preset-es2015 --save-dev 

現在你的WebPack您需要配置這些裝載機

var path = require('path'); 
var webpack = require('webpack'); 

module.exports = { 
    entry: './main.js', 
    output: { path: __dirname, filename: 'bundle.js' }, 
    module: { 
    loaders: [ 
     { 
     test: /.jsx?$/, 
     loader: 'babel-loader', 
     exclude: /node_modules/, 
     query: { 
      presets: ['es2015', 'react'] 
     } 
     }, 
     { 
     test: /\.css$/, 
     loader: "style-loader!css-loader" 
     }, 
     { 
     test: /\.png$/, 
     loader: "url-loader?limit=100000" 
     }, 
     { 
     test: /\.jpg$/, 
     loader: "file-loader" 
     }, 
     { 
     test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, 
     loader: 'url?limit=10000&mimetype=application/font-woff' 
     }, 
     { 
     test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, 
     loader: 'url?limit=10000&mimetype=application/octet-stream' 
     }, 
     { 
     test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, 
     loader: 'file' 
     }, 
     { 
     test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, 
     loader: 'url?limit=10000&mimetype=image/svg+xml' 
     } 
    ] 
    }, 
}; 

在此之後,您需要在入口文件中導入Bootstrap css,例如index.js,如

import 'bootstrap/dist/css/bootstrap.css'; 
+0

做一些你的步驟完成這兩行:'sudo npm install -g create-react-app'和'create-react-app hello-world'?因爲如果我這樣做和'npm install'和'npm start',我已經得到了一個具有'bundle.js'的應用程序,所以我懷疑webpack已經在工作了 –

+0

您可以檢查是否設置了引導裝載器您。我一直沒有使用create-react-app來初始化我的項目 –

相關問題