Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blahah/electron-renderify
Browserify transform to allow bundling for Electron renderer processes
https://github.com/blahah/electron-renderify
browserify browserify-transform electron nodejs
Last synced: 6 days ago
JSON representation
Browserify transform to allow bundling for Electron renderer processes
- Host: GitHub
- URL: https://github.com/blahah/electron-renderify
- Owner: blahah
- License: cc0-1.0
- Created: 2017-10-21T17:05:23.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T08:26:31.000Z (almost 2 years ago)
- Last Synced: 2024-10-08T14:12:29.072Z (about 1 month ago)
- Topics: browserify, browserify-transform, electron, nodejs
- Language: JavaScript
- Size: 115 KB
- Stars: 17
- Watchers: 2
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
---
---
Prefix calls to `require` as `window.require` for node and electron built-in modules. This allows them to work as you would expect in electron processes.
## Install
```
npm install electron-renderify
```## Usage
This module is to be used as a [browserify]() transform.
Depending on what is in your bundle, and how you are setting up Electron, you may need to apply some or all of the following browserify settings:
```js
{
builtins: [],
commonDir: false,
detectGlobals: false,
ignoreMissing: true,
insertGlobalVars: 'global',
browserField: false
}
```The best place to apply the settings is in your `package.json`. That way they will take effect with either CLI or JS api use.
### CLI
```bash
browserify -t electron-renderify sample.js > bundle.js
```### JS
```js
var browserify = require('browserify')
var renderify = require('electron-renderify')var path = require('path')
browserify()
.transform(renderify)
.add(path.join(__dirname, 'sample.js'))
.bundle()
.pipe(process.stdout)
```## Options
You can modify the behaviour of `electron-renderify` by passing options to the transform, like this:
```js
browserify()
.transform(renderify, opts)
```The following options are available:
### `opts.windowRequire` [Array[String]]
An array of strings, each of which specifies a module that should use `window.require` instead of plain `require`. This might be required for any native modules (although you should consider moving any such dependencies to the main process).
Example:
```js
var browserify = require('browserify')
var renderify = require('electron-renderify')var path = require('path')
var renderifyOpts = {
windowRequire: ['leveldown']
}browserify()
.transform(renderify, renderifyOpts)
.add('somefile-requiring-leveldown.js')
.bundle()
.pipe(process.stdout)
```## License
To the extent possible by law, we transfer any rights we have in this code to the public domain. Specifically, we do so using the [CC0 1.0 Universal Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/).
You can do whatever you want with this code. No need to credit us, link to us, include any license, or anything else. But if you want to do those things, you're free to do that too.