Skip to content

Instantly share code, notes, and snippets.

@HaykoKoryun
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HaykoKoryun/cdfb96894dee766381ed to your computer and use it in GitHub Desktop.
Save HaykoKoryun/cdfb96894dee766381ed to your computer and use it in GitHub Desktop.
npm install into a subfolder of your choice!

In your package.json file add the following two script declarations:

"scripts": {
    "preinstall": "node preinstall.js",
    "postinstall": "node postinstall.js"
},

In your entry script, add the followig code to make sure the working directory is set to the script so the node_modules folder resolves correctly:

process.chdir(__dirname);
var fs = require("fs");
try
{
if(process.platform.indexOf("win32") !== -1)
{
fs.unlinkSync("./node_modules/");
}
else
{
fs.unlinkSync("./node_modules");
}
}
catch(e){}
var fs = require("fs");
try
{
fs.mkdirSync("./app/node_modules/");
}
catch(e)
{
}
try
{
if(process.platform.indexOf("win32") !== -1)
{
fs.symlinkSync("./app/node_modules/","./node_modules/","junction");
}
else
{
fs.symlinkSync("./app/node_modules/","./node_modules","dir");
}
}
catch(e){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment