Comments (24)
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.
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.
!!!!!!!!!!! THANK YOU. I've been looking for a way to do that for some time now! This is awesome.
from blendid.
hehe :)
tell me if you had the same issues I had please
from blendid.
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.
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.
nice. thanks.
from blendid.
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.
@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.
@greypants I've updated my SO answer as I have more insights on this:
See http://stackoverflow.com/a/23608416/82609
from blendid.
@slorber thanks for documenting this!
from blendid.
Another possible option if there's hesitation to use path
s: https://github.com/joeybaker/remapify
from blendid.
thanks @solomonhawk I added it to my SO answer
from blendid.
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.
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.
Did you try?
var player = require('lib/player')
from blendid.
Right, I must have inadvertently moved /lib out of /js. Things seem to be functioning properly now.
from blendid.
Moved from browserifyi to webpack, so closing this out. The option in webpack is: resolve-modulesdirectories
from blendid.
By chance is it explained somewhere why you choose to replace browserify with webpack?
from blendid.
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.
I'm having issues with babelify caching my src/node_modules files, does anyone know how to get around that?
from blendid.
Is there a command line version of this?
from blendid.
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.
yes @Heliodromel it's just and env variable
from blendid.
Related Issues (20)
- watch task will not compile more than 48 html files HOT 5
- Removing "comments" from public/html files HOT 1
- xlink:href being deprecated in SVG
- Additional Tasks information HOT 4
- Build issue: UglifyJs - Unexpected token: name (context)
- Build issue: UglifyJs - Unexpected token: name (context) HOT 5
- Fonts aren't copied over on build HOT 1
- additionalTasks access rev-manifest HOT 4
- Not bundle jquery in production HOT 1
- Current project status HOT 4
- 4.5.0 release not available through npm/yarn HOT 1
- Failed to mount component: template or render function not defined HOT 1
- upgrade to gulp 4
- empty prebuild and postbuild configs must be `null`/`false`, not `[]`. change this behavior?
- html watch task does not notice changes to files added after Blendid was started
- wrong generation of path for js-files in rev-manifest on windows HOT 1
- Configuration for swiper to work
- The engine "node" is incompatible with this module HOT 3
- 4.5.3 release not available through npm HOT 1
- ERROR in bundle.js from UglifyJs Unexpected token: name (ChangeDesc) [bundle.js:2900,6]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blendid.