Webpack node global modules

时间:2015-12-01 08:28:11

标签: node.js webpack

How to configure webpack.config.js to global node modules support in browser?

I tried:

{
    global : true,
    process: true,
},

On build error occured:

can't find module 'fs'.

{
    fs: 'empty',
}

I tried call fs.existsSync(path) in js file. In browser error occured:

fs.existsSync is not a function.

1 个答案:

答案 0 :(得分:2)

你应该尝试将webpack的目标设置为节点,如下所示:

module.exports = {
 devtool: "source-map",
 target: "node",
 ...
}

这篇文章帮助了我很多:http://jlongster.com/Backend-Apps-with-Webpack--Part-I

  

目标:'节点'选项告诉webpack不要触摸任何内置的   模块如fs或path。