-
Notifications
You must be signed in to change notification settings - Fork 63
Conversation
@@ -19,12 +20,16 @@ | |||
"license": "MIT", | |||
"dependencies": { | |||
"debug": "^2.1.3", | |||
"fs": "0.0.2", |
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.
As a general note - this line here was missing on the earlier releases and caused a problem when I tried to use the latest 4.7.0
release in another project. It needs to be merged into master regardless of this PR.
dbc66fb
to
a042006
Compare
I tested within another project and called out for this branch specifically in the |
e8a2b04
to
91f1b0e
Compare
@@ -0,0 +1,23 @@ | |||
require("babel/register"); |
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.
Here and in a couple other places in the same file, there's some inconsistency on quotes and spacing around parentheses. The pattern I'm seeing elsewhere in the code base is single quotes, no spaces between parentheses.
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.
Some of this is lazy because I have another PR sitting out there to reformat everything using esformatter
. By the time I was writing this PR I assumed the formatting one would be merged already or that they would come at the same time.
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.
I fixed this case and will try and fix other places as well, thanks @aduth for your input!
ecbb036
to
ad8e82f
Compare
After lots of stewing and testing, I have decided to release this in the
To test the browser version I created an HTML file just like in I believe that this should be sufficient for our purposes here in that
|
What benefit is there to minifying the server-side variant? When you say the browser version depends on shims, are those included in the compiled version? It's important that a user be able to easily drop in the script without much effort. |
@aduth: There's not too much benefit to the node build to minimize, but we do need to run it through Babel if we don't want people having issues with the Promise code. In my tests, I ran webpack to bundle things and pass them through Babel. The result of this was some ridiculous source code because of the way webpack transformed the variable names Concerning Feel free to explore this issue yourself and commit here. I'm probably at the end of what I can productively offer concerning the npm package. |
Took another pass over the changes. A few thoughts:
|
I don't think we need Like I mentioned above I'm running webpack on both builds in order to bundle them. This produces a single output file instead of one for every source file. When I experimented with Babel anyway, it didn't change much (since we don't have much ES6 in our code) other than introduce the Babel shim dependency. The point of Babel is mainly to go from ES6 to ES5 syntax, whereas the point of webpack is to bundle and minify. Webpack just happens to make it easy to run the code through Babel in that process. Feel free to contribute a change though - like I said, I'm not an expert. One thing though is that we really don't have a server-side build. All of the builds are intended to be executed in the browser. The difference is that one is built as a CommonJS module to be loaded in a node environment and the other creates a As for the promises, I don't see any way of making them optional. They are core JS spec now and browser adoption should follow. The only way to remove this dependency is to include something like the core-js shim in the bundle, which would make it grow pretty big. |
I guess this is what I was confused about. It's obviously fine to use Webpack for the browser build, but I wasn't sure it would work (or be recommended) to use it for the server build. I've seen other projects using Webpack for the server build, but the Babel CLI for server builds (i.e. |
@retrofox: @aduth and I had a conversation in Slack earlier about how best to package the node-specific build of Produce a single-file bundle via webpackThis is the way I originally wrote up the PR and it uses the same pipeline for the browser-builds and the node-builds. The output is a single minified file and the accompanying source map. Run the individual library files through BabelThis is the way @aduth proposed and it copies all of the source files into a distribution directory, running each one through Babel. The output isn't minified and there are no source maps because the individual files differ from the original source only in that Babel has translated any ES6 features to ES5. Point and Counterpoint@aduth was concerned about the webpack build messing up the way the library works in node projects, since libraries like superagent behave differently in the different environments. I responded by mentioning that this doesn't impact There remains then probably a philosophical distinction: for node environments where people will presumably have a build system, do we provide the single minified file or the directory of un-minified files (16 in total). Neither one of us felt confident making a decision wherein we seem to prefer opposite methods. Do you have thoughts on this and could you guide the final PR organization? We are both fine going either direction. |
@aduth I have followed your recommendations here as best as I understand them and I think they are probably the best way to move forward here. In any case, I think we need to move forward because we still have a broken release out there to the public. As far as I can tell, running the code through Babel does not remove the need for the browser shim for promises. That will still be a requirement for the library, but I have that listed in the documentation in this PR. @retrofox do we think we can get this vetted and merged soon? P.S. The circleCI errors relate to the now-removed |
0b0783d
to
3078938
Compare
All that said, I am liking the new structure of |
@mattsherman if you want to take a look at @aduth's comments and push up a commit that would definitely help. I apologize because although I saw his comments ten days ago, I forgot about them since then. This is probably harder than it needs to be because we're doing two things: adding promises; and overhauling the build process into |
@dmsnell I'll look into things and push a commit that addresses the outstanding issues. |
Thanks @mattsherman - let me know if you have any questions - I'd be happy to help out. I think the highest priority right now would be to sit down and get the interactions between the |
6daec61
to
ec2330e
Compare
This patch changes the way the `wpcom.js` library is generated and built as a library by incorporating a **webpack**-based build system. Previously, when `wpcom.js` was imported into another project, the code that was hand-written was what made it into the dependent project. Previous coding style corresponded somewhat with this paradigm: skip whitespace to save bytes. Now, webpack is used to bundle up all of the constituent code, run it through a processor, and spit out the final and single file. This opens up new possibilities for the project including but not limited to: - Significant size reduction due to the way **webpack** optimizes and minifies the output code. For example, the previous standalone code was produced with **browserify** and was still a single file, but that file was around 100 KB. The new bundle produced by **webpack** is only 17 KB. - Function stripping: As a demonstration, for the standalone product I have imported a plugin into **webpack** that strips out calls to `debug`, `console.log`, and `console.warn`. This can be helpful for making a general-release build without the development hooks. - ES6 running natively in the library! The output bundle ends up pulling in a core-js shim, but we can use any ES6 functionality that might want, including Promises, spread/rest operators, template strings, destructuring, fat-arrow functions, and more. - Version bump from 4.7.0 to 4.7.1 to reflect the fact that the development and build system are completely new. - Updated `package.json` file with all required development dependencies. - Developers no longer mess with `index.js` in the root project directory. Instead, they should work in `wpcom.js`. The reason for this is that when `wpcom.js` gets included into another project, it's the `index.js` file that loads. Therefore, I chose to load in the processed and bundled version instead of the human-formatted one. - The `webpack.config.js` and `webpack.config.dist.js` files are related. The `dist` file simply extends the base configuration to produce something like what **browserify** used to create. While the base configuration is set to create a `commonjs2` module, the `dist` bundle will still remain in the `UMD` format. Console logging has also been removed from the standalone version. Ironically, these files won't work with ES6 syntax, so I have included the **babel** transform into the `dist` config so I can use `Object.assign()`. - It's important that we explicitly tell **webpack** which imported modules are external libraries otherwise it will try to merge them in and then we lose proper naming conventions and things break. - Before committing I tried testing with both the standalone and base bundles. You can try this by editing `test/util.js` and changing the top import statement to specify the exact file you want. - Is there a good reason to remove the console warnings in either the standalone or the base build? A reason not to? I didn't think that developers would appreciate the messages in the console, but maybe they would want the `debug()` statements... Include source-maps Set the module entry point in package.json Previously in order to accomodate the combiled webpack bundle I had to rename the existing `index.js` into `wpcom.js` so that the right file would import when loading this module. I have now discovered the "main" attribute for `package.json` and have used that here instead of renaming `index.js`. Now, the build stage produces `index.min.js` which is the compiled output that other scripts will load when they `require( 'wpcom' )` Catch up to changes in master
Rebased against master and added commits to address most of @aduth's comments... still need to test more and fix a failing test case (pretty sure this was failing before):
Done.
Still need to look into and address this.
Done.
Not addressed yet. If we do this, we'll have to maintain .gitignore and .npmignore -- do we want to do this?
Done.
This is actually expected (okay, not really expected, but accepted) behavior... npm/npm#3059. Removed |
@@ -5,3 +5,6 @@ npm-debug.log | |||
/gh-tmp | |||
.DS_Store | |||
.idea | |||
/dist/lib | |||
/dist/util | |||
/dist/test |
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.
Can't we just add /dist/
here or are there files we want to keep?
If, for example we want to keep the standalone file...
/gh-tmp
.DS_Store
.idea
/dist
!/dist/wpcom.js
That !
should whitelist the file
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.
Taken care of in 4a1cb85
@mattsherman I added a few comments here. Thanks for your work! |
Could it be the addition of the |
@aduth I added Maybe I was too hasty and fixed the wrong problem, but we definitely need to make sure that we don't end up in the same situation. |
we need |
it would be a half-court shot. |
@aduth @mattsherman @retrofox maybe we set an environment variable in webpack. By doing this, we could ignore the Is that code distinct @retrofox? Webpack actually has a loader to strip out certain calls. If the |
dist/index.js should be built when installed
…pcom.js into update/webpack-build-system
What do you mean ? distinct server-side that client-side? btw Cannot resolve module |
I've removed
And also I've updated the |
This must explain the problems I had getting it to run in @retrofox by distinct (which I realize was poorly worded) I meant was the code contained in its own function. If it were, it's pretty easy to replace that function at build-time. The alternative is that the platform-specific code is scattered among the universal code which would make it pretty ugly to pick apart. |
Changed to use `wpcom-oauth-cors` to auth user. Need to put client id and site in `examples/browser-cors/upload-images.html` in order to work.
Use webpack to build final product
This patch changes the way the
wpcom.js
library is generated and builtas a library by incorporating a webpack-based build system.
Previously, when
wpcom.js
was imported into another project, the codethat was hand-written was what made it into the dependent project.
Previous coding style corresponded somewhat with this paradigm: skip
whitespace to save bytes.
Now, webpack is used to bundle up all of the constituent code, run it
through a processor, and spit out the final and single file. This opens
up new possibilities for the project including but not limited to:
minifies the output code. For example, the previous standalone code
was produced with browserify and was still a single file, but
that file was around 100 KB. The new bundle produced by webpack
is only 17 KB.
have imported a plugin into webpack that strips out calls to
debug
,console.log
, andconsole.warn
. This can be helpful formaking a general-release build without the development hooks.
pulling in a core-js shim, but we can use any ES6 functionality that
might want, including Promises, spread/rest operators, template
strings, destructuring, fat-arrow functions, and more.
Major changes
development and build system are completely new.
package.json
file with all required developmentdependencies.
index.js
in the root projectdirectory. Instead, they should work in
wpcom.js
. The reason forthis is that when
wpcom.js
gets included into another project, it'sthe
index.js
file that loads. Therefore, I chose to load in theprocessed and bundled version instead of the human-formatted one.
Special notes
The
webpack.config.js
andwebpack.config.dist.js
files arerelated. The
dist
file simply extends the base configuration toproduce something like what browserify used to create. While the
base configuration is set to create a
commonjs2
module, thedist
bundle will still remain in the
UMD
format. Console logging hasalso been removed from the standalone version.
Ironically, these files won't work with ES6 syntax, so I have
included the babel transform into the
dist
config so I can useObject.assign()
.It's important that we explicitly tell webpack which imported
modules are external libraries otherwise it will try to merge them in
and then we lose proper naming conventions and things break.
Before committing I tried testing with both the standalone and base
bundles. You can try this by editing
test/util.js
and changing thetop import statement to specify the exact file you want.
Questions
standalone or the base build? A reason not to? I didn't think that
developers would appreciate the messages in the console, but maybe
they would want the
debug()
statements...dist
standalone build anymoresince the root
index.js
is now a processed bundle? Of course, we don't haveto replace
index.js
from what it was, but I think this makes integration intoother projects better because they won't get the code bloat and they won't run
into issues with ES6 syntax.
them? I wouldn't see why we wouldn't, but since they didn't already exists I didn't
change it.
cc: @retrofox @TooTallNate