使用webpack-dev-server时,webpack build中缺少bundle.js [英] bundle.js missing from webpack build when using webpack-dev-server
问题描述
我看了类似但却无法找到一个解决我问题的答案。我找不到bundle.js文件,即使我指定它应该输出到哪里,一切都在浏览器中工作。据我所知,webpack-dev服务器正在从内存中加载文件而没有任何内容被写入磁盘,我如何获取文件并将其添加到配置文件中output属性中指定的目录?
I looked at similar but couldnt find a concerete answer that resolved my issue. I can't find the bundle.js file even though I am specifying where it should be outputted and everything works in the browser. I understand that the webpack-dev server is loading the files from memory and nothing is being written to disk, how I can get the file to be built and added to the dir specified in the output property in the config file?
这是我的package.json:
Here is my package.json:
{
"name": "redux-simple-starter",
"version": "1.0.0",
"description": "Simple starter package for Redux with React and Babel support",
"main": "index.js",
"repository": "git@github.com:StephenGrider/ReduxSimpleStarter.git",
"scripts": {
"start": "./node_modules/webpack-dev-server/bin/webpack-dev-server.js -- content-base build"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"react-hot-loader": "^1.3.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "^4.0.0",
"redux": "^3.0.4"
}
}
webpack config:
webpack config:
var path = require('path');
var webpack = require('webpack');
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./src/index.js'
],
output: {
path: path.join(__dirname, 'assets'),
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel'
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
contentBase: './'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
};
推荐答案
此Webpack 插件强制服务器将捆绑包写入磁盘。
This Webpack plugin forces the server to write the bundle to disk.
虽然我同意Austin和lux,如果您需要将文件放在磁盘中,请直接致电webpack。
Although I agree with Austin and lux, if you need to have the file in disk, call webpack directly.
这篇关于使用webpack-dev-server时,webpack build中缺少bundle.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!