requirejs optimizer window is not defined error

I am making an app which is using node, backbone and requirejs together. I need to optimize the js but I am running into the error Reference Error: Window is not defined when I try to run the optimized file using node through command prompt.

I searched for solutions and read about plugin-builder and also found an example, but I am not sure exactly how to make that thing work.

I have my main file main.js in which I have defined config for requirejs(paths,shim etc.) and a build.js for optimizer in which I have defined the parameters for optimizing

({
    baseUrl: ".",
    mainConfigFile: 'main.js',
    name: "main",
    out: "main-built.js"
})

Any help on how to proceed further?