deepak1556 / gulp-browserify

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

external bundle is replace with an hash #59

Closed yanns closed 10 years ago

yanns commented 10 years ago

I am trying to declare a module as external like that:

    gulp.src([paths.src + '/main/app/main.js'])
        .pipe(browserify({
            debug: gutil.env.type !== 'production',
            transform: ['reactify'],

            // do not concat react in our javascript, let it external
            // it means that the react javascript must be included in the html
            // with the same version as the react dependency in package.json
            external: ['react']
        }))

Sample app: https://github.com/yanns/react-unit-test/blob/master/gulpfile.js#L39

It kind of works, as the react lib is not concatenated with my application javascript. But, in the generated javascript, the module name for react is replaced with an hash like that:

"react":"TTpHcX"

leading to an error in the browser: Uncaught Error: Cannot find module 'TTpHcX'

I tried a lot of different configurations, included those found in https://github.com/deepak1556/gulp-browserify/issues/55

I tried to define alias, but without any success at the moment. Is it a problem with gulp-browersify, or with my configuration?

Thanks for any help.

shuhei commented 10 years ago

It's fine that an external module has a hash. In order to make it work, you need another bundled script with { require: ['react'] }. Please see node-browserify's README for more details of external and require.

One of my personal projects was doing something relevant. I set react as a dependency in package.json, created lib.js whose content is just require('react'); and made it bundled with browserify.

yanns commented 10 years ago

Thanks for the help. I am just surprise that I cannot override this hash.