I was trying to use browserify on a file that uses the fs object. When I browserify it, the call to require('fs')
doesn't get transformed and require
returns {}
.
Is there any workaround for this? I've seen some suggestions on stackoverlow and elsewhere, but none seem to be fully realized.
I actually hoped to create a google web packaged app using browserify for a class I teach.
Thanks in advance.
Browserify is an open-source JavaScript bundler tool that allows developers to write and use Node. js-style modules that compile for use in the browser.
js file system module allows you to work with the file system on your computer. To include the File System module, use the require() method: var fs = require('fs');
This is a browserify transform which works similarly to react-hot-loader. Once you run you app in the browser, it monitors your JavaScript code and only updates the changed component, preserving the state of the application.
If you want to inline file contents from fs.readFileSync()
calls, you can use brfs:
var fs = require('fs'); var src = fs.readFileSync(__dirname + '/file.txt');
then do:
browserify -t brfs main.js > bundle.js
and src
will be set to the contents of file.txt
at compile time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With