1

如何node_modules从运行中排除?

摩卡-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\"",

4

1 回答 1

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 
...
};
于 2016-08-26T11:30:49.727 回答