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

Minify JSON #471

Merged
merged 3 commits into from
Jan 6, 2018
Merged

Minify JSON #471

merged 3 commits into from
Jan 6, 2018

Conversation

DeMoorJasper
Copy link
Member

closes #400 closes #399

@DeMoorJasper DeMoorJasper changed the title Feature/json minify Minify JSON Jan 2, 2018
transform() {}
async transform() {
if (this.options.minify) {
this.contents = minify(this.contents, {
Copy link

Choose a reason for hiding this comment

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

Should check the minify() result for error.

https://github.com/mishoo/UglifyJS2/tree/harmony#api-reference

Copy link

Choose a reason for hiding this comment

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

for example:

let result = minify(code, options);
if (result.error) {
throw result.error;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

let result = minify(code, options);
if (result.error) {
throw result.error;
}
// Log all warnings
if (result.warnings) {
result.warnings.forEach(warning => {
// TODO: warn this using the logger
console.log(warning);
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we intentionally skipping any custom config for JSON?

let customConfig = await config.load(asset.name, ['.uglifyrc']);

Seems a lot of this could be consolidated with the uglify transform.

Copy link

Choose a reason for hiding this comment

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

result.warnings is not interesting in parsing JS expressions - result.error is sufficient as it's a binary pass/fail operation. The warnings apply to the uglify compressor which is not applicable here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@brandon93s i don't think anyone would want to change this behaviour, as it just removing some quotes and whitespace

Copy link
Member Author

Choose a reason for hiding this comment

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

@kzc i'll throw the errors, forgot about those

@devongovett
Copy link
Member

Refactored slightly to make JSONAsset not inherit from JSAsset anymore. Seems like that had the potential to break more things than it helped with as we add more stuff to JSAsset that doesn't apply to JSON.

@devongovett devongovett merged commit c858843 into parcel-bundler:master Jan 6, 2018
@DeMoorJasper DeMoorJasper deleted the feature/json-minify branch January 6, 2018 19:33
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* uglify-json

* throw on error

* Clean up JSONAsset

Don’t extend from JSAsset
devongovett pushed a commit that referenced this pull request Oct 15, 2018
* uglify-json

* throw on error

* Clean up JSONAsset

Don’t extend from JSAsset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 JSON files don't get minified
4 participants