2016-05-16 341 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的服务器”