JWally / jsLPSolver

Simple OOP javaScript library to solve linear programs, and mixed integer linear programs
The Unlicense
420 stars 69 forks source link

make production library work in browser and node #14

Closed JWally closed 9 years ago

JWally commented 9 years ago

Would like to have 1 file work in the browser environment (raw and asm) and in Node as well. Currently have 2 versions in existence (1 at prod/solver.js and the other at src/solver.js)

JWally commented 9 years ago

@bchevalier here's what I'm thinking of doing to fix the issue of needing 2 files to work in 2 environments; question is would it mess you up too much?

  1. I'll rename src/solver.js to src/main.js
  2. I'll make it so running grunt prod will produce a browserfied version of the project at src/solver.js. This way, the entry point to the project is always at src/solver.js. This keeps the project from breaking anything that uses it as a dependency
  3. At the bottom of the new browserfied src/solver.js file, I'll append a piece of code that looks something like this:
  (function(){
    // Only execute if we're in node
    if(typeof module === "object"){
    // Have this file act as a facade
    // for src/main.js, which houses the
    // guts of this project
      module.exports = require("./main");
    }
  })()

'4. Some time in the future remove the prod directory

Currently, the browserfied version of solver.js returns a blank object in the node environment. I think this'll fix that issue.

bchevalier commented 9 years ago

This is solution is fine by me, and if you think that will do it then go for it.

bchevalier commented 9 years ago

By the way, could you make a new npm release?

JWally commented 9 years ago

Done

On Mon, Oct 19, 2015 at 5:01 AM, Brice notifications@github.com wrote:

By the way, could you make a new npm release?

— Reply to this email directly or view it on GitHub https://github.com/JWally/jsLPSolver/issues/14#issuecomment-149172300.

bchevalier commented 9 years ago

thanks!