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

Added dedicated webpack entry point. #1318

Merged
merged 1 commit into from Mar 3, 2017

Conversation

@worldsense-tms
Copy link
Contributor

@worldsense-tms worldsense-tms commented Jan 13, 2017

I'm using Bluebird 3.4.7 with webpack 1 and noticed it was clobbering the global variable P. I could see the snippet at the end of the script that it puts itself in the global namespace.

                       ;if (typeof window !== 'undefined' && window !== null) {
                             window.P = window.Promise;
                        } else if (typeof self !== 'undefined' && self !== null) {
                             self.P = self.Promise;
                        }

I investigated a bit and found out that webpack will use the "browser" field from package.json if it's available. From the webpack docs:

Check these fields in the package.json for suitable files.
Default: ["webpack", "browser", "web", "browserify", ["jam", "main"], "main"]

This means that webpack picks the "browser" version instead of "main". Running webpack --display-modules confirmed it:

[5] ./~/bluebird/js/browser/bluebird.js 178 kB {0} [built]

Since Blubird's installation docs do not mention it, I think it's expected to include release/bluebird.js from the main field.

@worldsense-tms
Copy link
Contributor Author

@worldsense-tms worldsense-tms commented Feb 14, 2017

I was able to work around this with an alias in webpack.config.js:

alias: {
  'bluebird': 'bluebird/js/release/bluebird'
}

Perhaps you'd like to change the installation docs instead?

@petkaantonov petkaantonov merged commit 8d52820 into petkaantonov:master Mar 3, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@le0nik
Copy link

@le0nik le0nik commented Mar 16, 2017

For those confused why it doesn't work in webpack 2, default mainFields are different in it

mainFields: ["browser", "module", "main"]

In order to make this work you need to specify them manually

mainFields: ["webpack", "browser", "module", "main"]

An alternative(which I was using prior to this PR) would be to use an alias for bluebird:

resolve: {
  alias: {
    bluebird: path.join(__dirname, './node_modules/bluebird/js/release/bluebird.js'),
  }
}

P.S.: Now you can also decrease bundle size by stripping unneeded modules from it like so:

    new webpack.NormalModuleReplacementPlugin(  /\/node_modules\/bluebird\/js\/release\/(?:assert|each|settle|using|any|race|call_get|filter|generators|nodeify|promisify|map|reduce|settle|some|progress)(?:\.js)?$/,
      path.join(__dirname, './node_modules/lodash/noop.js')
    ),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants