我的項目中的webpack成功運行,但是當我到達所需的端口時,它會顯示目錄文件。你可以看到相同的圖像。Webpack成功編譯但在瀏覽器中不顯示輸出
我webpack.config.js
const path = require('path');
module.exports = {
entry: './app/main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
devServer: {
inline: true,
port: 8100
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}
]
}
}
的package.json
{
"name": "react_router",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server"
},
"author": "vinay",
"license": "ISC",
"dependencies": {
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router": "^2.0.1"
},
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^2.6.1",
"webpack-dev-server": "^2.4.5"
}
}
main.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './app'
ReactDOM.render(<App />, document.getElementById('root'));
app.js
import React, {Component} from 'react';
import {Router, Route, Link, IndexRoute, hashHistory, browserHistory} from 'react-router';
const App =() => <h1>Hello World</h1>
export default App
輸出==>
任何幫助,將不勝感激。
您沒有用於顯示webpack-dev-server的'index.html'文件。添加一個'index.html'文件,並帶有指向你的包的鏈接。 – nrgwsth
我在App目錄中有index.html文件。但是,我如何將它添加到捆綁包? –
您需要在'index.html'中提供'bundle'腳本url – nrgwsth