Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Use webpack for builds #78

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Use webpack for builds #78

wants to merge 11 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 8, 2015

This breaks json3.js into separate CommonJS modules that are stitched together with webpack. The source files are usable as separate modules—requiring them imports the make* factories that return the exported methods—but it's a little tricky with runInContext, has, and our export system. For now, I just added a webpack WrapperPlugin that wraps the build in build/assets/{header, footer}.js.

Various functions from build.js have also been moved into their own modules. I investigated switching to gulp (4.0 adds a lot of nice conveniences), but held off for now...we're using a lot of custom, non-streaming transforms, and I don't think we need one-off gulp-json3-* plugins. getCompiler and friends have been removed entirely; Bower can download and cache the Closure Compiler for us.

@D10 I'd love your feedback, whenever you have some spare cycles. I expect this will need a lot more polish before it's ready for merging. 😸

There is a slight increase in the size of the minified version, but I think it's acceptable—especially if we can do custom builds in the future that remove some of the corner cases (e.g., Date#toJSON fixes).

Build master feature/webpack
Dev 41.47 KB 40.84 KB
Minified 3.46 KB 3.62 KB

}
var serializeDate = makeSerializeDate(UTCDate);
if (has("json-stringify")) {
// TODO: Revert via `JSON3.noConflict()`.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this work with noConflict is going to be interesting, since noConflict isn't a module, but a browser-only function that's injected by the webpack WrapperPlugin. We'd need to make noConflict context-aware...

var destPath = path.join(__dirname, "lib", "json3.min.js");
writeMinified(srcPath, destPath, function afterMinify(err, fileSizes) {
if (err) {
console.error("Error compressing JSON 3: %s", err);
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be callback(err)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! 👓

Kit Cambridge added 11 commits April 9, 2015 11:48
* Add `makeRunInContext`.
* Modularize `build.js`.
* Use Bower to download the Closure Compiler.
Expose `noConflict` in CommonJS environments. Add an optional
`preventNoConflict` flag to `runInContext` that controls whether
`noConflict` is a no-op. This flag is used when exporting for CommonJS
environments, where the global scope is not modified.
Add missing `nextTask` callback to `compress`.
@ghost ghost mentioned this pull request Apr 9, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

1 participant