简体   繁体   中英

Webpack - Output Files are not generating

I am creating a simple react app using webpack as the bundler and nodejs for creating a server. The thing is my webpack is not generating the output files in the destination folder. I am not seeing any error and http://localhost:3000 shows my expected content, but the dist folder is not generated.

Is this something related to hot-module-reloding, and webpack is generating everything from memory for me. I am not sure. I am new to react and any help will be highly appreciated.

Thanks

webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-dev-server/client?http://localhost:3000',
    'webpack/hot/only-dev-server',
    './src/index'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/static/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [{
      test: /\.js$/,
      loaders: ['react-hot', 'babel'],
      include: path.join(__dirname, 'src')
    }]
  }
};

package.json

 "scripts": {
    "start": "node server.js",
    "lint": "eslint src"
  },
//remaining dependencies

server.js

var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config');

new WebpackDevServer(webpack(config), {
  publicPath: config.output.publicPath,
  hot: true,
  historyApiFallback: true
}).listen(3000, 'localhost', function (err, result) {
  if (err) {
    return console.log(err);
  }

  console.log('Listening at http://localhost:3000/');
});

您应该使用“ webpack”而不是“ webpack-dev-server”,因为“ webpack”确实会将代码生成到磁盘,而“ webpack-dev-server”只是将代码提供给本地主机

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM