使用Webpack Shell插件时“检测到可能的EventEmitter内存泄漏”

时间:2016-09-20 09:22:51

标签: node.js npm webpack

我正在使用Webpack Shell Plugin在Webpack构建完成后运行脚本。

但是,当我运行Webpack时,我会收到以下警告:

(node:91967) Warning: Possible EventEmitter memory leak detected. 11 unpipe listeners added. Use emitter.setMaxListeners() to increase limit
(node:91967) Warning: Possible EventEmitter memory leak detected. 11 drain listeners added. Use emitter.setMaxListeners() to increase limit
(node:91967) Warning: Possible EventEmitter memory leak detected. 11 error listeners added. Use emitter.setMaxListeners() to increase limit
(node:91967) Warning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit
Running onBuildExit

这是我的插件配置:

config.plugins.push(new WebpackShellPlugin({
    onBuildExit: [
        "echo 'Running onBuildExit'",
        "cp file1.js dist/file1.js",
        "cp file2.js dist/file2.js",
        "cp file3.js dist/file3.js",
        "cp file4.js dist/file4.js",
        "cp file5.js dist/file5.js",
    ]
}))

这些警告的原因是什么?如何解决?

1 个答案:

答案 0 :(得分:0)

这并没有解决根本原因,但我的解决方案是将各个命令合并为一个更长的脚本。

config.plugins.push(new WebpackShellPlugin({
    onBuildExit: [
        `
        echo 'Running onBuildExit'
        cp file1.js dist/file1.js
        cp file2.js dist/file2.js
        cp file3.js dist/file3.js
        cp file4.js dist/file4.js
        cp file5.js dist/file5.js
        `
    ]
}))