GithubHelp home page GithubHelp logo

Comments (24)

brianmriley avatar brianmriley commented on May 20, 2024 1

Thanks! This was huge, especially when trying to use browserify-shim on bower dependencies like angular.

package.json

"browser": {
    "angular": "../client/libs/vendor/angular/angular.js"
},
"browserify": {
    "transform": ["browserify-shim"]
},
"browserify-shim": {
    "angular": "angular"
}

gulpfile.js

var srcDir = "../client/src/app/";
var libDir = "../client/libs/";
var vendorDir = libDir + "vendor/";
var buildDir = "../dist/dev/";

gulp.task("browserify", function() {
    return browserify({
            entries: srcDir + "ApplicationModule",
            paths: [vendorDir]
        })
        .bundle()
        .pipe(source("app.js"))
        .pipe(gulp.dest(buildDir));
});

from blendid.

slorber avatar slorber commented on May 20, 2024

Some useful things to read about this:
browserify/browserify#767
(I had problems using the transforms declaration inside package.json, like mentionned at the end)

browserify/browser-resolve#41
browserify/browser-resolve#42

from blendid.

greypants avatar greypants commented on May 20, 2024

!!!!!!!!!!! THANK YOU. I've been looking for a way to do that for some time now! This is awesome.

from blendid.

slorber avatar slorber commented on May 20, 2024

hehe :)

tell me if you had the same issues I had please

from blendid.

slorber avatar slorber commented on May 20, 2024

hello @greypants

still not in gulp starter? :) maybe i'll do a PR then

Btw I've done a project inspired by your gulp starter that you may mention on your Readme for interested users:

https://github.com/stample/gulp-browserify-react-phonegap-starter

from blendid.

Rodeoclash avatar Rodeoclash commented on May 20, 2024

This isn't a requirement for me but it would be good to see pull requests like this making it into the repo. At the moment this project has been the best (and simplest) setup of Gulp that I've found.

@greypants have you thought about adding other contributors to the repo? (like @slorber) I'd hate to see the repo stagnate :)

from blendid.

chasevida avatar chasevida commented on May 20, 2024

nice. thanks.

from blendid.

greypants avatar greypants commented on May 20, 2024

Thanks for reminding me about this. I've been hesitant to immediately add it, since it's not a documented browserify option. Is there a good reason for that? It certainly is super useful, but I wanted to take some time to think about any negative implications before adding it. Can you guys think of any? Naming conflicts is the only one I can think of.

from blendid.

slorber avatar slorber commented on May 20, 2024

@greypants I use this in a real application and didn't have any problem until now.

You can find it there too:
https://github.com/stample/gulp-browserify-react-phonegap-starter
https://github.com/stample/gulp-browserify-react-phonegap-starter/blob/master/gulp/tasks/browserify.js

This works fine for me. As I use relative paths that are relative to my src folders, I do not use simple requires like require("someModule") but it's rather require("someSrcPath/subPath/someModule") thus it's improbable that I get a conflict.

But it may happen if you name one of your own module express and put it in the src root and require it with require("express"): I don't know at all the behavior in this case, maybe it depends on the list order

from blendid.

slorber avatar slorber commented on May 20, 2024

@greypants I've updated my SO answer as I have more insights on this:
See http://stackoverflow.com/a/23608416/82609

from blendid.

LeonB avatar LeonB commented on May 20, 2024

@slorber thanks for documenting this!

from blendid.

solomonhawk avatar solomonhawk commented on May 20, 2024

Another possible option if there's hesitation to use paths: https://github.com/joeybaker/remapify

from blendid.

slorber avatar slorber commented on May 20, 2024

thanks @solomonhawk I added it to my SO answer

from blendid.

EvanCarroll avatar EvanCarroll commented on May 20, 2024

Perhaps gulp-started needs to be updated with this?

https://github.com/gulpjs/gulp/blob/master/docs/recipes/fast-browserify-builds-with-watchify.md

from blendid.

rossthedevigner avatar rossthedevigner commented on May 20, 2024

I'm having a bit of an issue with this as well as I don't want '../../../' all over my files. In my browserify task, I have the following config

var config = {
  // Enable source maps
  debug: true,
  // Additional file extensions to make optional
  extensions: ['.js'],
  // A separate bundle will be generated for each
  // bundle config in the list below
  bundleConfigs: [{
      entries: './app/js/index-app.js',
      dest: './app/js',
      outputName: 'app.js',
      paths: ['./node_modules', './app']
  }]
}

And in my index-app.js, I'm trying to include a module:

var player = require('./lib/player');

But when I run gulp scripts for testing, this error occurs:

[12:53:05] Starting 'scripts'...
[12:53:05] Bundling app.js
[12:53:05] gulp-notify: [Compile Error] Cannot find module './lib/player' from '/git/player/app/js'
[12:53:05] Bundled app.js in 106 ms
[12:53:05] Finished 'scripts' after 136 ms

Since I'm specifying a root path, I'm confused as to why ./lib does not work with the following structure:

./app
  /js
   index-app.js
   /lib
     player.js

from blendid.

mykone avatar mykone commented on May 20, 2024

Did you try?

var player = require('lib/player')

from blendid.

rossthedevigner avatar rossthedevigner commented on May 20, 2024

Right, I must have inadvertently moved /lib out of /js. Things seem to be functioning properly now.

from blendid.

greypants avatar greypants commented on May 20, 2024

Moved from browserifyi to webpack, so closing this out. The option in webpack is: resolve-modulesdirectories

from blendid.

slorber avatar slorber commented on May 20, 2024

By chance is it explained somewhere why you choose to replace browserify with webpack?

from blendid.

greypants avatar greypants commented on May 20, 2024

Blog post forthcoming perhaps. In short, it's way more powerful. You can output multiple bundles, extract shared dependencies into a shared bundle, async module loading is silly easy, it's smart about dynamic requires, and more. Been using it for almost a year now and haven't looked back.

from blendid.

rjdlee avatar rjdlee commented on May 20, 2024

I'm having issues with babelify caching my src/node_modules files, does anyone know how to get around that?

from blendid.

dimes avatar dimes commented on May 20, 2024

Is there a command line version of this?

from blendid.

Heliodromel avatar Heliodromel commented on May 20, 2024

Hello, i'm also looking for a command line version for this path option. Any tips ?
EDIT: actually it seems that we can do the following "NODE_PATH=./modules browserify App.js"
It worked for me.

from blendid.

slorber avatar slorber commented on May 20, 2024

yes @Heliodromel it's just and env variable

from blendid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.