Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Use npm link for local development #4

Open
alexsegura opened this issue Aug 31, 2017 · 1 comment
Open

Use npm link for local development #4

alexsegura opened this issue Aug 31, 2017 · 1 comment

Comments

@alexsegura
Copy link
Member

We need to document & improve how to work locally, using npm link.

For example, right now when I work on the coopcycle-bot project , here is what I do:

cd /path/to/coopcycle-js
npm link
cd /path/to/coopcycle-bot
npm link coopcycle-js

This creates a symbolic link in node_modules for the coopcycle-js project.
I still need to run npm run build inside the coopcycle-js folder to reflect the changes.

@Ledoux
Copy link
Contributor

Ledoux commented Sep 27, 2017

@alexsegura
several things:

  • npm run link is a slow process for just symlinking stuff, actually a linux like
    ln -sf is faster and works like a charm normally, when your dependencies in both repos have similar versioning.
  • quick solution is to add in coopcycle-bot a dev command "npm run dev" that should look like this:
"scripts": {
    "dev-symlink": "cd node_modules && ln -sf ../../coopcycle-js .",
    "dev-watch-coopcycle-js": "cd ../coopcycle-js && npm run dev",
    "dev-pm2":  "./node_modules/.bin/pm2 start pm2.config.js",
    "dev": "npm run dev-symlink && npm run dev-watch-coopcycle-js && npm run dev-pm2",
    "watch": "webpack-dev-server --content-base=web/"
  }

and in pm2 config, add a watch on the coopcycle-js build

module.exports = {
  apps: [{
    "name" : "coopcycle-bot",
    "script" : "./index.js",
    "watch": env === 'development' ? ["./index.js", "./src/*.js", "./node_modules/coopcycle-js/build"] : false,
    "env_production" : {
      "NODE_ENV": "production"
    }
  }]
}

Note that:

  • it supposes you have coopcycle-js at this good ../ directory (but normally it is, based on the repo structure)

  • pm2 actually is a bin command available in the local node_modules... so no need to install it globally

  • last thing: in the repo coopcycle-js, you need to create your watching dev command

"scripts": {
    "example": "webpack-dev-server --content-base=example/",
    "build": "webpack -p",
    "dev": "nodemon --watch src --exec \"npm run build\""
  },

(by adding like "nodemon": "^1.11.0" in devDependencies)

and things should be synchronized.

  • BUT the process and the sync is very slow like this! You trigger a complete webpack build, that is a bit overkill, because you may only want actually the last updates on the Client class definition only defined in client.js, if I am not wrong (this is the only part used by the coopcylcle-bot)?
    BEST PRACTICE should be to extract from coopcycle-js the code that you need for both repos, that looks like utils, and create therefore a small lib with the Client Class definition, shared with symlinks like this for both coopcyle-bot and coopcycle-js repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants