deepak1556 / gulp-browserify

Bundle modules with BrowserifyJS
MIT License
195 stars 45 forks source link

Upgrade to browserify-shim v3 API #53

Open JHKennedy4 opened 10 years ago

JHKennedy4 commented 10 years ago

Allows support for shimming libraries loaded via cdn, would also allow you to reference their current docs.

deepak1556 commented 10 years ago

@shuhei can we drop support for shim and allow using via transforms ?

shuhei commented 10 years ago

@deepak1556 Yeah, it would be nice to deprecate it first showing warning and drop it later.

jgrowl commented 10 years ago

Does the browserify-shim transform currently work? Is there an example how to configure it?

deepak1556 commented 10 years ago

@jgrowl there is an example in #48 by @shuhei , will doc in readme soon.

shuhei commented 10 years ago

@jgrowl This plugin does nothing to transforms. See browserify-shim's README for examples.

jgrowl commented 10 years ago

@shuhei @deepak1556 Ahh, thanks. I was getting thrown off because when I added "browserify-shim" to my transforms in my gulpfile I was getting Error: browserify-shim needs to be passed a proper browserify instance as the first argument.

If I add the configuration purely in the package.json file, all seems good.

gaastonsr commented 10 years ago

Just to make it clear for future reference:

  1. Install browserify-shim (npm install --save-dev browserify-shim)
  2. Put all config in package.json. See browserify-shim's README for examples.
  3. Register the transform with gulp-browserify (transform: ['browserify-shim'])
JHKennedy4 commented 10 years ago

Thanks! On Feb 13, 2014 9:14 PM, "gaastonsr" notifications@github.com wrote:

Just to make it clear for future reference:

  1. Install browserify-shim (npm install --save-dev browserify-shim)
  2. Put all config in package.json. See browserify-shim's READMEhttps://github.com/thlorenz/browserify-shimfor examples.
  3. Register the transform with gulp-browserify (transform: ['browserify-shim'])

Reply to this email directly or view it on GitHubhttps://github.com/deepak1556/gulp-browserify/issues/53#issuecomment-35049389 .

mwmaleks commented 10 years ago

Hi, every body! I'm tying to use browserify-shim with karma and encounter such error: Error: browserify-shim needs to be passed a proper browserify instance as the first argument.

The same thing I've got when use broserify from command line. Here is my package.json part:

"browserify": {
        "transform": [ "browserify-shim" ]
},
"browser": {
        "jquery"    :  "./client/requires/jquery/js/jquery.js",
        "bootstrap" :  "./client/requires/bootstrap/bootstrap.js"
},
"browserify-shim": {
        "jquery"    :  "$",
        "bootstrap" :  {"exports": null, "depends": [ "jquery" ] 
}

my file mainSpec.js to be browserifed looks this way:

...
var someModule = require('path/to/module');
require('bootstrap');
...

then in command line $ broserify mainSpec.js -o bundleSpec.js I use browserify v 2.36.1 and browserify-shim v 2.0.10

Could some body, please, tell me what I do wrong? And how to solve it?

deepak1556 commented 10 years ago

@mwmaleks use browserify-shim v3

mwmaleks commented 10 years ago

Thank you! Now it works!

apfelbox commented 10 years ago

I still encounter issues with browserify-shim, but only when using it with gulp-browserify.

My package.json

{
    "browserify": {
        "transform": [ "browserify-shim" ]
    },
    "browserify-shim": {
        "jquery": "global:jQuery"
    },
    "devDependencies": {
        "browserify": "^4.2.0",
        "browserify-shim": "^3.6.0",
        "gulp": "^3.8.5",
        "gulp-browserify": "^0.5.0"
    }
}

(I tried it with and without the browserify-part)

My gulpfile.js

var gulp       = require("gulp");
var browserify = require("gulp-browserify");

gulp.task("default",
    function ()
    {
        return gulp.src("in/*.js")
            .pipe(browserify({
                transform: ['browserify-shim']
            }))
            .pipe(gulp.dest("out/"));
    }
);

How I tried it

The CLI works just fine:

~/Desktop/gulp $ ./node_modules/.bin/browserify in/*.js
(function e(t,n,r){......

Gulp doesn't work however:

~/Desktop/gulp $ gulp
[19:47:20] Using gulpfile ~/Desktop/gulp/gulpfile.js
[19:47:20] Starting 'default'...

.../Desktop/gulp/node_modules/gulp-browserify/node_modules/browserify-shim/index.js:16
    throw new Error('browserify-shim needs to be passed a proper browserify in
          ^
Error: browserify-shim needs to be passed a proper browserify instance as the first argument.
 you passed:'.../Desktop/gulp/in/fake_7b97708d.js'

Exact versions:

~/Desktop/gulp $ npm ls --depth 0
@ ~/Desktop/gulp
├── browserify@4.2.0
├── browserify-shim@3.6.0
├── gulp@3.8.5
└── gulp-browserify@0.5.0

@deepak1556 any idea?

ghost commented 10 years ago

I ran into the same issue as @apfelbox today.