如何排除“node_modules”

时间:2016-08-26 11:19:52

标签: webpack mocha mocha-webpack

如何从运行中排除node_modules

mocha-webpack

我认为webpack-node-externals意味着这项任务。这是我的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;

我从package.json运行测试:

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

1 个答案:

答案 0 :(得分:0)

添加以下代码并查看注释以获取详细信息。 有关详细信息,请参阅此链 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 
...
};