Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserify (+ babelify): it is impossible to share code #1357

Closed
gaydenko opened this issue Aug 18, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@gaydenko
Copy link

commented Aug 18, 2015

Hi!

In a word: how to share lib between browserify/babelify projects?
At the moment I have:

prj1
  node_modules
    lib (symlink to share/lib)
  src (es6 files are here)
  package.json
  gulpfile.js
prj2
  node_modules
    lib (symlink to share/lib)
  src (es6 files are here)
  package.json
  gulpfile.js
share
  lib
     package.json
     shared es6.js files

Here share/lib/package.json is just:

{
  "browserify": {
    "transform": ["babelify"]
  }
}

The aim is to share share/lib/*.js between prj1 and prj2. With the aim I have added symlinks to share/lib/ from prjN/node_modules/lib directories. But modules can not be found.

Where is my mistake?

P.S. Was not lucky to get an answer on SO, the last hope is here :)

@gaydenko gaydenko changed the title [Q] browserify + babelify - how to share lib? [Q] browserify + babelify: how to share lib? Aug 18, 2015

@gaydenko gaydenko changed the title [Q] browserify + babelify: how to share lib? browserify (+ babelify): it is impossible to share code Aug 21, 2015

@mattdesl

This comment has been minimized.

Copy link
Contributor

commented Aug 28, 2015

Instead of symlinking to a shared folder, you should just use regular modules to share code between projects.

import { someFunction } from 'my-shared-module'
console.log(someFunction())

Where my-shared-module folder structure looks like this:

my-shared-module
  package.json
  index.js (es6)

For it to be consumed properly it needs babelify as a browserify transform.

{
  "browserify": {
    "transform": ["babelify"]
  }
}

Then, from your project folder, you can npm link ../my-shared-module to symlink it properly as a module during development. Once the shared code is stable, you can npm install --save my-shared-module instead of linking it.

https://docs.npmjs.com/cli/link
http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears

@gaydenko

This comment has been minimized.

Copy link
Author

commented Aug 28, 2015

Thanks, will play with npm link.

@gaydenko gaydenko closed this Aug 28, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.