Jonathan Ong
Jonathan Ong

Reputation: 20325

webpack exits without any error codes if a module is missing

I see the error message - it's red - but i'd like it to return a non-zero exit code so i know it errored out. what configuration am i missing? I am not using the no errors plugin

'use strict'

const webpack = require('webpack')
const path = require('path')

const babel_cache_path = require('../config/babel').cache_path
const port = require('../config').port

module.exports = {
  entry: {
    index: './client/index',
    dev: [
      'webpack-dev-server/client?http://localhost:' + (port + 1),
      'webpack/hot/only-dev-server',
    ],
  },
  output: {
    path: path.resolve('build'),
    publicPath: 'http://localhost:' + (port + 1) + '/',
    filename: '[name].js',
    chunkFilename: '[id].[name].js',
  },
  plugins: [
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
    }),
    new webpack.HotModuleReplacementPlugin(),
    // new webpack.NoErrorsPlugin(),
  ],
  resolve: {
    extensions: [
      '',
      '.js',
      '.jsx'
    ]
  },
  module: {
    loaders: [
      // babel + jsx loader
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: [
          `babel?cacheDirectory=${babel_cache_path}`
        ]
      },
      // json loader
      {
        test: /\.json$/,
        loaders: [
          'json'
        ]
      },
      // css loader
      {
        test: /\.css$/,
        loaders: [
          'style',
          'css?modules&sourceMap&importLoaders=1&localIdentName=[path][name]---[local]---[hash:base64:5]',
          'postcss'
        ]
      }
    ],
  },
  postcss () {
    return require('postcss-jongleberry')({
      minify: false
    })
  },
  // no node builtins
  node: false
}

Upvotes: 2

Views: 2084

Answers (1)

Preview
Preview

Reputation: 35816

Adding the --bail cli option or bail: true in your config should return a valid error exit code, but it seems that some people are having issues in webpack 1.* versions with it.

There is a specific module that have been created for this sole purpose, webpack-fail-plugin

npm i webpack-fail-plugin

And then add it in your webpack plugins config.

Upvotes: 3

Related Questions