0

Is it possible to run the command browserify file.js > bundle.js without using the command prompt ?

Can I run this command from a javascript file?

robertklep
  • 198,204
  • 35
  • 394
  • 381
ameni
  • 393
  • 2
  • 8
  • 17
  • 2
    Did you [read the fine manual](https://github.com/substack/node-browserify#api-example)? – robertklep Dec 16 '15 at 14:57
  • @Vohuman if i create .js file and require browserify, i have to use the command prompt to run this file with " node file.js" but i should not use the command prompt, is it possible to create .js file which call the command prompt and generate the browserify file? – ameni Dec 16 '15 at 15:01
  • http://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js – Nathaniel Johnson Dec 16 '15 at 15:01
  • @ameni if you want a .js file that calls the command prompt, how are you going to execute _that_ .js file? – robertklep Dec 16 '15 at 15:04
  • @robertklep i just want to have this .js file which will be integrated in a javascript program – ameni Dec 16 '15 at 15:07
  • @ameni so what's wrong with running the code I linked to from your JS program? – robertklep Dec 16 '15 at 15:08
  • Did the answer to that question help? – Nathaniel Johnson Dec 16 '15 at 15:09
  • @robertklep i have this command browserify file.js > bundle.js : i want to execute it without using manually the command prompt, so exist any solution to integrate this command in a javascript program(which i can call it from html) so this js program call the command prompt of node js and execute this instruction browserify file.js > bundle.js without the need of opening cmd manually – ameni Dec 16 '15 at 15:13
  • I suspect the real question is "Can I run browserify from the client browser?" and the short answer is No. Browserify depends on modules in node that are not available in the client environment. If you run node as a server, you could send the un-browserfied code back to the server, compile it, and send it back to client. – Nathaniel Johnson Dec 16 '15 at 17:17

2 Answers2

0

It sounds like you are looking for something like gulp. (http://gulpjs.com/)

Here's a good article to get you started: https://viget.com/extend/gulp-browserify-starter-faq

Ryan D
  • 42
  • 2
  • 11
  • i have this command browserify file.js > bundle.js : i want to execute it without using manually the command prompt, so exist any solution to integrate this command in a javascript program(which i can call it from html) so this js program call the command prompt of node js and execute this instruction browserify file.js > bundle.js without the need of opening cmd manually – ameni Dec 16 '15 at 15:20
  • Gulp could help me to do this? – ameni Dec 16 '15 at 15:20
  • Running `gulp watch` with the following task would allow browserfy to continually build on any source code edits: https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-transforms.md Note: You still need to add a `gulp watch` task that would invoke the `javascript` task in the above link. – Ryan D Dec 16 '15 at 15:35
  • to run gulp watch i should use the command prompt node.js ? because i souldn't use it manually, it should be launched automatically on background – ameni Dec 16 '15 at 15:47
0

I think if you use script tag in package.json

"scripts": { "start": "browserify file.js -o bundle.js" },

it may work without using command prompt

Actung
  • 1,438
  • 1
  • 13
  • 18
  • i just add this in my package.json? then how can i execute it to get the bundle.js – ameni Dec 16 '15 at 21:08
  • You just have to run a command in the beginning, which in this case is `npm compile start` where 'start' is the script name. This will create bundle.js. But I don't know if you can avoid using command prompt. – Actung Dec 17 '15 at 14:44