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

Available as an ECMAScript module? #616

Open
SebastianKohler opened this issue May 31, 2023 · 4 comments
Open

Available as an ECMAScript module? #616

SebastianKohler opened this issue May 31, 2023 · 4 comments
Assignees

Comments

@SebastianKohler
Copy link

Hi,

First of all, thank you for a great package!

I'm using this in an Angular 15 project. Angular points out that JSON→URL is a CommonJS module, which can prevent bundlers and minifiers from optimizing my application, which results in a larger bundle size. It recommends not to depend on CommonJS modules and instead use ECMAScript modules.

Any chance of an ECMAScript module of JSON→URL?

@dmaccormack dmaccormack self-assigned this Sep 14, 2023
@dmaccormack
Copy link
Collaborator

Hi, @SebastianKohler.

JSON→URL is already available as a module. This test shows a example: https://github.com/jsonurl/jsonurl-js/blob/main/itest/es6-native/main.js#L25.

How are you referencing it?

@SebastianKohler
Copy link
Author

Thanks for your reply!

I use it in a service in Angular like this:

import { Injectable } from '@angular/core';
import JsonURL from '@jsonurl/jsonurl';


@Injectable({
  providedIn: 'root',
})
export class UrlService {
    constructor() {}

    parse(text: string, impliedArray: boolean = false): any {
        return JsonURL.parse(text, {
            AQF: true,
            ...(impliedArray && { impliedArray: [] })
        });
    }

    stringify(value: any, impliedArray: boolean = false): string | undefined {
        return JsonURL.stringify(value, {
            AQF: true,
            ...(impliedArray && { impliedArray: true })
        });
    }

}

@dmaccormack
Copy link
Collaborator

Where is the warning message coming from (e.g. the bundler) and what is the exact message you're seeing?

@SebastianKohler
Copy link
Author

Warning: C:\Users\sebkoh\Documents\GitHub\digital_edition_web_ng\src\app\services\url.service.ts depends on '@jsonurl/jsonurl'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

It's the Angular @angular-devkit/build-angular builder that produces the warning. It's displayed every time my Angular app is built.

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