Webpack node global modules

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.

Upvotes: 1

Views: 3755

Answers (1)

Moff
Moff

Reputation: 46

you should try and set the target for webpack to node, with something like this:

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

This post helped me alot: http://jlongster.com/Backend-Apps-with-Webpack--Part-I

The target: 'node' option tells webpack not to touch any built-in modules like fs or path.

Upvotes: 2

Related Questions