简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM