Bundle.js文件不是由webpack为生产版本生成的

时间:2018-04-30 11:05:55

标签: reactjs webpack redux

我无法生成bundle.js文件。

  

这是我的webpack.config.js。

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
  path: __dirname,
  publicPath: '/',
  filename: 'bundle.js'
},
module: {
  loaders: [{
    exclude: /node_modules/,
    loader: 'babel',
    query: {
      presets: ['react', 'es2015', 'stage-1']
    }
  }]
},
resolve: {
  extensions: ['', '.js', '.jsx']
},
devServer: {
  historyApiFallback: true,
    contentBase: './'
  }
};
  

这是我的package.json

{
"name": "redux-react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
  "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
  "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
  "test:watch": "npm run test -- --watch"
},
"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",
  "chai": "^3.5.0",
  "chai-jquery": "^2.0.0",
  "jquery": "^2.2.1",
  "jsdom": "^8.1.0",
  "mocha": "^2.4.5",
  "react-addons-test-utils": "^0.14.7",
  "webpack": "^1.12.9",
  "webpack-dev-server": "^1.14.0"
},
"dependencies": {
  "babel-preset-stage-1": "^6.1.18",
  "lodash": "^3.10.1",
  "react": "^0.14.3",
  "react-dom": "^0.14.3",
  "react-redux": "4.3.0",
  "react-router": "^2.0.1",
  "redux": "^3.0.4"
} 
}

主要目的是构建一个生产就绪的应用程序,因此如何配置我的webpack以生成bundle.js文件。还有必要为dev和生产服务器分别使用webpack.config吗?

1 个答案:

答案 0 :(得分:1)

webpack-dev-server用于开发目的。这不会将您的bundle.js放在您的工作目录中,它会在内存中编译您的文件。 我可以从您的包脚本中看到您正在运行webpack-dev-server来构建代码