Skip to content

minified constructor parameter names after production-build #36

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

Closed
civilizeddev opened this issue Jun 24, 2019 · 10 comments
Closed

minified constructor parameter names after production-build #36

civilizeddev opened this issue Jun 24, 2019 · 10 comments

Comments

@civilizeddev
Copy link
Contributor

Description

Some packaging-for-production-distribution libraries, such as react-scripts (used by create-react-app), pkg (Node Binary Packager), minify JS file on its variable names. With it constructor parameter names are not preserved. It makes @JsonProprty() on constructor parameters not working.

Any idea on this?

@GillianPerard
Copy link
Owner

Hi!

For the moment I haven’t.

Could you try to pass the real json name to JsonProperty ?

constructor(@JsonProperty(‘name’) public name: string) {}

@GillianPerard
Copy link
Owner

Hi, thank you for the PR, I'll test it as soon as possible.

Could you just provide me how did you test with a minifier please ?

@civilizeddev
Copy link
Contributor Author

Steps to reproduce

I tested it on my react application, but it is also used in server side. For now I'll describe it for client side only.

  1. Create a project using create-react-app
  2. Define a data model class (e.g. Student) with properties on constructor parameters with typescript-json-serializer decorators.
  3. It is enough just with index.tsx and Student.ts.
  4. Write a pair of serialize/deserialize code on index.tsx.
  5. Try yarn build to make a production-build, which will minify the code.
  6. Run it on local web server.
  7. Open Chrome DevTools and check the console. (Finished)

@civilizeddev
Copy link
Contributor Author

I think it is good to prepare the minified code before the test phase starts.
Could you do that on gulpfile.js?

@GillianPerard
Copy link
Owner

Thanks for the test flow.

Honestly I don't know, let me check.

@civilizeddev
Copy link
Contributor Author

I'm looking forward to hearing from you.

@GillianPerard
Copy link
Owner

GillianPerard commented Jun 29, 2019

Hi,

If I try to use decorators in CRA project, when I try to get design:type it always returns undefined and break my lib.

Capture d’écran 2019-06-29 à 08 39 28

You don't have any errors on your side ? If no, how did you do that ? ^^'

PS: It seems to be a Babel limitation

@civilizeddev
Copy link
Contributor Author

No, it works very well on my side.

I made a pull request for poc of this.

@GillianPerard
Copy link
Owner

GillianPerard commented Jul 2, 2019

Hi, I made some modifications and it works for CRA but it still not work for angular.

I'm investigating.

EDIT: I've checked and it seems that AOT removes custom decorators from constructor and there is no solution for the moment, then Angular users may only use JsonProperty on property directly and not on constructor params (https://github.com/angular/angular-cli/issues/9306).
Let me know if #38 is good for you, then I'll publish it.

@civilizeddev
Copy link
Contributor Author

It's good for me. Thanks.

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

No branches or pull requests

2 participants