webpack-dev-server退出,状态码为1

时间:2018-05-05 21:30:50

标签: reactjs npm webpack webpack-dev-server package.json

我有三个文件webpack.config.base,webpack.config.dev,webpack.config.prod及相应的代码:

** webpack.config.base **

const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const parentDir = path.join(__dirname, '../');

module.exports = {
  entry: [
    path.join(parentDir, 'index.js'),
  ],
  resolve: {
    extensions: ['.js', '.jsx', '.json'],
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      },
      {
        test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
        use: [
          {
            loader: 'image-webpack-loader',
            options: {
              bypassOnDebug: true,
            },
          },
          'url-loader?limit=10000',
        ],
      },
      {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'sass-loader'],
        }),
      },
    ],
  },
  output: {
    path: `${parentDir}/dist`,
    filename: 'bundle.js',
  },
  plugins: [
    new ExtractTextPlugin({
      filename: 'main.css',
    }),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
    }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
  ],
};

** webpack.config.dev **

    const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');

const parentDir = path.join(__dirname, '../');
const config = require('./webpack.config.base.js');

module.exports = merge(config, {

  devServer: {
    inline: true,
    colors: true,
    progress: true,
    hot: true,
    open: true,
    bail: true,
    quiet: true,
    contentBase: parentDir,
    port: 7070,
    historyApiFallback: true,
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
  ],
});

生产:

const webpack = require('webpack');

const config = require('./webpack.config.base.js');

config.plugins = config.plugins.concat([
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
  new webpack.DefinePlugin({
    'process.env.NODE_ENV': JSON.stringify('production'),
  }),
]);

module.exports = config;

package.json中的脚本是

 "dev": "./node_modules/.bin/webpack-dev-server --mode development --config ./webpack/webpack.config.dev.js",

使用npm run dev webpack dev服务器退出,状态代码为-1。任何人都可以告诉我哪里出错了?我正在使用的版本是:

"webpack": "^4.6.0",
"webpack-cli": "^2.1.2",
"webpack-dev-server": "^3.1.4"

Error:

提前致谢。我已经尝试在单个文件中使用它,它运行良好,但如果在三个不同的文件中这样划分,那么它会产生此错误。所有这些文件都在根目录下的webpack文件夹中。

1 个答案:

答案 0 :(得分:0)

这三个选项产生了一个问题:

bail: true,
quiet: true,
colors: true

我删除了,现在工作正常。如果有人能够更新它为什么会如此,那么将有助于进一步理解。