Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

browserify bundle electron app main process file

I am building a electron app and currently using browserify for the renderer (web page) files like any other javascript front end. I would like to also use browserify to bundle the main process files. However, browswerify is unable to find the electron built in modules like clipboard, ipc, browser-window, app, etc...

In my main.js file which serves as the entry point for the electron app. I have:

const ipc = require('ipc');
const clipboard = require('clipboard');
const BrowserWindow = require('browser-window');
const app = require('app');
const yargs = require('yargs');

the const yargs loads fine as it is in the node_modeuls folder and browserify can resolve that. However the othe four items cannot be found by browserify and therefore fail my build.

[11:49:17] Finished 'development' after 17 ms
Error: Cannot find module 'ipc' from '<path>'
Error: Cannot find module 'clipboard' from '<path>'
Error: Cannot find module 'browser-window' from '<path>'
Error: Cannot find module 'app' from '<path>'

Any suggestions?

like image 869
Kyle Avatar asked Nov 21 '15 17:11

Kyle


People also ask

How do I debug my Browserify bundles?

Use tinyify for optimized, tree-shaked bundles in production environments. Use --debug when creating bundles to have Browserify automatically include Source Maps for easy debugging.

How do I use Browserify on the command line?

Here is a tutorial on how to use Browserify on the command line to bundle up a simple file called main.js along with all of its dependencies: Browserify parses the AST for require () calls to traverse the entire dependency graph of your project. Drop a single <script> tag into your html and you're done!

What is the difference between tinyify and Browserify?

Browserify parses the AST for require () calls to traverse the entire dependency graph of your project. Drop a single <script> tag into your html and you're done! Use watchify, a browserify compatible caching bundler, for super-fast bundle rebuilds as you develop. Use tinyify for optimized, tree-shaked bundles in production environments.

How can i Improve my Browserify development?

Use tinyify for optimized, tree-shaked bundles in production environments. Use --debug when creating bundles to have Browserify automatically include Source Maps for easy debugging. Check out tools like Beefy or run-browser which make automating browserify development easier.


1 Answers

With browserify you can set the options 'ignoreMissing' and 'detectGlobals' which allow browserify to ignore built int modules that eventually get loaded automatically in the electron app.

browserify({
    entries: './src/main.js',
    extensions: ['.js'],
    ignoreMissing: true,
    detectGlobals: false,
    bare: true,
    debug: false
})
like image 63
Kyle Avatar answered Sep 25 '22 08:09

Kyle