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.
答案 0 :(得分:2)
你应该尝试将webpack的目标设置为节点,如下所示:
module.exports = {
devtool: "source-map",
target: "node",
...
}
这篇文章帮助了我很多:http://jlongster.com/Backend-Apps-with-Webpack--Part-I
目标:'节点'选项告诉webpack不要触摸任何内置的 模块如fs或path。