2016-05-16 345 views
1

編輯:原因是我運行webpack-dev-server,運行時只有webpack它工作。React,Webpack:沒有生成bundle.js

我正在使用React和Webpack。未生成bundle.js。我發現this question on SO提出了相同的問題,但我似乎有安裝所需的依賴項。這裏是我的webpack.config.js:

var webpack = require('webpack');  
module.exports = { 
    entry: [ 
     'webpack-dev-server/client?http://localhost:8080', 
     'webpack/hot/only-dev-server', 
     './src/index.js' 
    ], 
    module: { 
     loaders: [{ 
      test: /\.js?$/, 
      exclude: /node_modules/, 
      loader: 'react-hot!babel' 
     }] 
    }, 
    resolve: { 
     extensions: ['', '.js'] 
    }, 
    output: { 
     path: 'dist', 
     publicPath: '/', 
     filename: 'bundle.js' 
    }, 
    devServer: { 
     contentBase: './dist', 
     hot: true 
    }, 
    plugins: [ 
     new webpack.HotModuleReplacementPlugin() 
    ] 
}; 

這裏是我的package.json:

{ 
    "name": "plump", 
    "version": "1.0.0", 
    "description": "", 
    "main": "index.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "repository": { 
    "type": "git", 
    "url": "git+https://github.com/fiskpatte/plump.git" 
    }, 
    "keywords": [], 
    "author": "", 
    "license": "ISC", 
    "babel": { 
    "presets": [ 
     "es2015", 
     "react" 
    ] 
    }, 
    "bugs": { 
    "url": "https://github.com/fiskpatte/plump/issues" 
    }, 
    "homepage": "https://github.com/fiskpatte/plump#readme", 
    "devDependencies": { 
    "babel-core": "^6.8.0", 
    "babel-loader": "^6.2.4", 
    "babel-preset-es2015": "^6.6.0", 
    "babel-preset-react": "^6.5.0", 
    "react-hot-loader": "^1.3.0", 
    "webpack": "^1.13.0", 
    "webpack-dev-server": "^1.14.1" 
    }, 
    "dependencies": { 
    "history": "^2.1.1", 
    "react": "^15.0.1", 
    "react-dom": "^15.0.1", 
    "react-router": "^2.4.0" 
    } 
} 

任何想法?

編輯。輸出運行時的WebPack:

       Asset  Size Chunks    Chunk Names 
          bundle.js 1.19 MB  0 [emitted] main 
0.63b359d04fe48d6168fa.hot-update.js 27.9 kB  0 [emitted] main 
63b359d04fe48d6168fa.hot-update.json 36 bytes   [emitted] 
chunk {0} bundle.js, 0.63b359d04fe48d6168fa.hot-update.js (main) 1.11 MB [rendered] 
    [318] ./src/components/LoginPage.js 8.93 kB {0} [built] 
    [322] ./src/components/Lobby.js 12.2 kB {0} [built] 
    [323] ./src/components/SignUp.js 5.6 kB {0} [built] 
    [324] ./src/pages/Game.js 27.3 kB {0} [built] 
    + 321 hidden modules 
webpack: bundle is now VALID. 
+1

當您運行的WebPack的輸出是什麼? – Kannaj

+0

我編輯了這個問題。 Wierd,它似乎是在生成契約,但我沒有找到它當我搜索計算機 – hellogoodnight

回答

3

即使世界可能出錯的輸出路徑..你可以嘗試更換到./dist

+0

我試過了,但該文件仍然不存在 – hellogoodnight

+1

你運行的是webpack-dev-server還是隻是webpack? – Kannaj

+0

webpack-dev-server – hellogoodnight

1

這是由於包裝的腳本時的一些鍵值對的缺失輸出路徑以.json。用以下代碼替換您的腳本對象:

"scripts": { 
    "start": "npm run build", 
    "build": "webpack -p && webpack-dev-server" 
    }, 

「-p」特別指webpack.config.js的生產環境。然後運行CMD這個:$ npm start

$ npm start將調用CMD npm run build這反過來將調用「的WebPack -p & &的WebPack-dev的服務器」