W3cubDocs

/webpack

mocha-loader

[![npm][npm]][npm-url] [![node][node]][node-url] [![deps][deps]][deps-url] [![tests][tests]][tests-url] [![chat][chat]][chat-url]

mocha loader module for webpack

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install mocha-loader:

$ npm install mocha-loader --save-dev

Then add the loader to your webpack config. For example:

// webpack.config.js
module.exports = {
  entry: './entry.js',
  output: {
    path: __dirname,
    filename: 'bundle.js'
  },
  module: {
    rules: [{
      test: /test\.js$/,
      use: 'mocha-loader',
      exclude: /node_modules/,
    }]
  }
}

Then import the target file somewhere in your app:

// src/entry.js
import test from './test'

And run webpack via your preferred method.

Examples

You can also use the loader via:

CLI

webpack --module-bind 'mocha-loader!./test'

Require

import test from 'mocha-loader!./test'

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING CONTRIBUTING" class="icon-link" href="#contributing">

License

MIT MIT" class="icon-link" href="#mit">

© JS Foundation and other contributors
Licensed under the Creative Commons Attribution License 4.0.
https://webpack.js.org/loaders/mocha-loader