Friday 14 April 2017

How to use a javascript project in our node project?

As I'm beginning to grasp the world of javascript as a client/server language (up to now it's all been C#), I would like to know how could I have an existing project as part of my own project so I can call it internally and not after it's loaded in the client.

using js-cookie project, and taken that I have:

/libs
  app.ts
/dependencies
  js-cookie.js
/dist
 app.js
gruntfile.js
server.js
package.json

I would love to do:

import * as JsCookies from './../dependencies/js-cookie.js'

export default class MyProject {

    get_cookie(name: string):string {
        return JsCookie.get(name);
    }

    set_cookie(name: string, value: string, expires?: number): void {
        if (typeof expires === "number")
            JsCookie.set(name, value, { expires: expires });
        else
            JsCookie.set(name, value);
    }

    // ...
}

in short, abstract my own project of handling cookies and use the js-cookie project for that, and let webpack minimize it and obfuscating it.

How could I achieve such thing?



via balexandre

No comments:

Post a Comment