1

I want to customize the Parse SDK. They provide source through an npm module, which makes it usable in node environments.

How can I compile this node module into a standalone parse.js script which will run as it is on a browser?

I tried using browserify as

browserify ./parse -o parse.js 

but the parse.js it spits out is quite large and still contains node remanents: process and require commands. Although it executes without any error on browser, the browser cannot find Parse definition.

1
  • It's large because it adds browser compatible process and so on. What do you have in parse.js? Commented Nov 25, 2015 at 11:44

2 Answers 2

3

Found the correct way to compile the parse npm module into a browser script is to use:

browserify path/to/npm/parse --standalone parse > parse-browser.js 

For any other script it should be :

browserify path_to_module --standalone global_name_to_expose > output.js 

Also, since the parse node module has a lot of node code, I would recommend people to use envify followed by uglify to make their code more optimized.

Sign up to request clarification or add additional context in comments.

Comments

0

AFAIK, Parse-module doesn't expose itself as a browser global. You should have a file, such as app.js that contains your definitions and use that to require the Parse module.

For example:

//app.js var Parse = require("parse"); console.log(Parse) 

Bundle it (the bundle will contain your app.js and the contents of the parse-module:

browserify ./app.js -o app.bundle.js 

and include the bundled file to your HTML file

<script src="app.bundle.js" 

After you open your HTML file, you should see the Parse object in your console.

1 Comment

Parse does expose the Parse method/class globally. Thanks anyway ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.