-
Notifications
You must be signed in to change notification settings - Fork 342
Module browser bundle configuration using webpack #48
Conversation
@schrepfler: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/ |
To trigger the build one just launches |
At the moment I'm not sure if the generated bundle is ideal for consumption from </script> tags. Would be nice if a webpack expert suggests what's missing and also confirm will npm publish publish the browser bundle automatically or not? |
I think at the moment the bundle is not properly created, don't merge just yet (and if anyone has suggestions feel free to comment on the PR.) |
I think with this final commit, the generated bundle is usable in a browser via a script tag
and
generates a tgz which contains it so I suppose this is more/less what we want? |
The only thing which actually comes to mind, if subscriptions_transport_ws imports things from graphql-subscriptions and they finish in the bundle, it might be possible to say that these need to be provided as linked scripts from the outside (declare them external in webpack) but at this point I think it's better for you guys to evaluate. |
Any feedback on this would be nice? |
@schrepfler sorry, this fell off of my radar for a while. I think we should definitely implement it, but it looks like you're compiling things twice now (once with TS once with webpack). Couldn't webpack just use the output from TS and bundle for the browser after that? @rricard I think you know this library (and also js in general 😄 ) pretty well. Could you take a quick look at this PR and help @schrepfler where necessary? That would be awesome! |
@helfer thanks for directing me to this issue. @schrepfler I'm going to do a proper review of your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you did works 🎉 (by eyeballing it, we'll need to actually publish it to be sure it really works... Like you I'm concerned about the peer dependency on graphql-subscriptions) so it's pretty cool, although, I have to nitpick on some stuff! Fix that and I'll be able to merge you!
package.json
Outdated
@@ -24,7 +26,8 @@ | |||
"testonly": "mocha --reporter spec --full-trace ./dist/test/tests.js", | |||
"coverage": "node ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js", | |||
"postcoverage": "remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info", | |||
"prepublish": "npm run compile" | |||
"start": "webpack --config webpack.config.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't call this script start, something more meaningful: browser-compile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
webpack.config.js
will be called by default so just put "webpack"
in the script invocation
package.json
Outdated
@@ -24,7 +26,8 @@ | |||
"testonly": "mocha --reporter spec --full-trace ./dist/test/tests.js", | |||
"coverage": "node ./node_modules/istanbul/lib/cli.js cover _mocha -- --full-trace ./dist/test/tests.js", | |||
"postcoverage": "remap-istanbul --input coverage/coverage.raw.json --type lcovonly --output coverage/lcov.info", | |||
"prepublish": "npm run compile" | |||
"start": "webpack --config webpack.config.js", | |||
"prepublish": "npm run compile && npm run start" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of start
, put browser-compile
webpack.config.js
Outdated
output: { | ||
path: __dirname + '/browser', | ||
filename: 'bundle.js', | ||
library: 'subscriptions_transport_ws' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually exported libs are in pascal case: 'SubscriptionsTransportWs'
, please do that!
webpack.config.js
Outdated
@@ -0,0 +1,18 @@ | |||
module.exports = { | |||
context: __dirname + "/src", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use path.join
instead of a concatenation
webpack.config.js
Outdated
context: __dirname + "/src", | ||
entry: './index.ts', | ||
output: { | ||
path: __dirname + '/browser', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use path.join
instead of a concatenation
webpack.config.js
Outdated
library: 'subscriptions_transport_ws' | ||
}, | ||
resolve: { | ||
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just ['.ts', '.js', '.json']
?
@@ -2,7 +2,7 @@ | |||
|
|||
### vNEXT | |||
|
|||
- ... | |||
- Webpack configuration to export the generated code into a browser compatible bundle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: reference this PR number in the changelog
@helfer I'm concerned about the dependency on |
@schrepfler On our side we should only expose the client module, so your entry point should only be: |
@rricard thanks a lot for tuning in here! ❤️ We can definitely (and probably should) make graphql-subscriptions a peer dependency. |
package.json
Outdated
@@ -10,8 +10,10 @@ | |||
"dependencies": { | |||
"backo2": "^1.0.2", | |||
"graphql-subscriptions": "^0.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so while we're here, can you move this one in devDependencies
and peerDependencies
.
Went over the suggestions, only problem was with |
Ah, I also bumped a bit the libraries, but notably typed-graphql and graphql to get in line with the rest of the apollo stack. Anyhow, merry xMas! |
Would the addition of |
@rricard If a module is never imported in the code, webpack will not include it in the bundle. Declaring it as a peer dependency has no effect regarding webpack, but the externals config does (although not needed here, since The only difference is that users of this package will have to manually install |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems better, I still need to test it before shipping it though...
@rricard can you please review the reversal of the change and comment on the runtime vs devDependencies wrt json and ts-loaders? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me, I just need to check a few things first but once it's done, let's ship it!
Shall we try to ship it and then try to catch up with the rest of the apollo js stack? 😀🚀🛫🍻 |
@schrepfler I meant that instead of creating a new Webpack config file and compile the package for browser, we might be able to do the same bundle process from the compiled files, since they're no longer coupled. |
Not sure what's going on, the rebase went into a loop, so tried to do the merge manually. |
Somehow the new versions popped back into package.json. Hopefully it's good now. |
@schrepfler , thanks for the rebase. What about using the compiled client file, and then just bundling it? |
I think this is the case, the only thing webpack is bundling is the client.ts? https://github.com/apollographql/subscriptions-transport-ws/pull/48/files#diff-11e9f7f953edc64ba14b0cc350ae7b9d |
Also, please consider this has been submitted on the 15th November 2016 and JS is not my main skill, can we wrap it up? I don't mind if you use mine bundle or if you have your bundle.
|
@schrepfler sorry it took a long time, the other PR was pretty big and I was working on it while implementing subscriptions on one of our internal apps. |
I think this is the case, I wrap client.ts which is then exposed as SubscriptionsTransportWs in the global scope if added to the page. I think |
I just realised you're the same guy from the JSJabber podcast episode I just listened, nice one! :D |
Any feedback in order to understand further course of actions? |
I'll close this PR and start over. |
thanks again @schrepfler , linking the merged one if someone will stumble upon this one - #77 |
Only thing I can see is that the bundle is being created but I don't have the skills to really test this (sorry, Java/Scala guy here).
This feature should enable simple CDN-like referencing via https://unpkg.com/ while keeping the publishing to npm as a basis. Related to #47
TODO: