2

How can I exclude node_modules from the run?

mocha-webpack

I thought that webpack-node-externals were meant for this task. This is my webpack.test-config.js:

const nodeExternals = require('webpack-node-externals');
const config = {};

// in order to ignore built-in modules like path, fs, etc.
config.target = 'node';

// in order to ignore all modules in node_modules folder
config.externals = [nodeExternals()];

config.output = {
    // sourcemap support for IntelliJ/Webstorm
    devtoolModuleFilenameTemplate: '[absolute-resource-path]',
    devtoolFallbackModuleFilenameTemplate: '[absolute-resource-path]?[hash]'
};

// 'cheap-module-source-map' faster than 'source-map'
config.devtool = "source-map";


module.exports = config;

I run the tests from package.json:

"test": "mocha-webpack --webpack-config webpack.config-test.js \"**/test/*.test.js\"",

Amio.io
  • 20,677
  • 15
  • 82
  • 117

1 Answers1

0

Add the below code and see comments for details. See this link for detail: https://www.npmjs.com/package/webpack-node-externals

var nodeExternals = require('webpack-node-externals');
...
module.exports = {
...
target: 'node', // in order to ignore built-in modules like path, fs,     etc. 
externals: [nodeExternals()], // in order to ignore all modules in   node_modules folder 
...
};
Omer Malik
  • 409
  • 7
  • 15
  • Man, that's the very same I already have. Only I have assigned the object to a variable `config`. ;) – Amio.io Aug 26 '16 at 11:37