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

switch from webpack to swc #2

Merged
merged 7 commits into from
Dec 20, 2023
Merged

switch from webpack to swc #2

merged 7 commits into from
Dec 20, 2023

Conversation

erikyo
Copy link
Collaborator

@erikyo erikyo commented Dec 18, 2023

No description provided.

@erikyo
Copy link
Collaborator Author

erikyo commented Dec 19, 2023

ATM everything works except umd export. don't know, suggestions? @johnhooks do you think i should export * as default in index.ts to get it working? or do you think i am missing something? umd module is necessary to run this package in the browser I would not want to leave it behind, any suggestion?

--- edited ---
an additional idea can be to export the script for the browser as
globalthis.isoToLanguage = {...}

Copy link

@johnhooks johnhooks left a comment

Choose a reason for hiding this comment

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

LGTM!

@erikyo
Copy link
Collaborator Author

erikyo commented Dec 19, 2023

Ha! you haven't seen the last changes :P

i managed to build the optimized version for ESM - CJS - UMD - browser only, I just have to look into it later because I have to figure out how to make a single export that works for everything. maybe making a glue file as I wrote before is the best solution

that because i can export in this way

globalThis.isoToLanguage = {
    format : format,
    getAll : getAll,
    getAllLanguageCodesByISO : getAllLanguageCodesByISO,
    getAllLanguagesByISO : getAllLanguagesByISO,
    getCountriesByISO : getCountriesByISO,
  ...
}

and for the browser the functions will be available under window like window.isoToLanguage.getAll()

and in this way

globalThis.format = format;
globalThis.getAll = getAll;
globalThis.getAllLanguageCodesByISO = getAllLanguageCodesByISO;
globalThis.getAllLanguagesByISO = getAllLanguagesByISO;
globalThis.getCountriesByISO = getCountriesByISO;
globalThis.getCountriesByLanguage = getCountriesByLanguage;
  ...

and for the browser the functions will be available under window like window.getAll(). Would be cool but in this case some functions needs to be renamed to avoid potential collisions with other plugins (e.g. moment)

@erikyo
Copy link
Collaborator Author

erikyo commented Dec 19, 2023

i need to type the umd/browser scripts in this way 👇 and exclude from swc the ./src/isoToLanguage.ts and we are ready to go.

declare global {
  function myFunction(): boolean;
  var myVariable: number;
}

adds the clean script to delete the lib folder then with concurrently builds the packages and then the types
@erikyo erikyo merged commit 1bca6b6 into master Dec 20, 2023
2 checks passed
@erikyo erikyo deleted the swc branch January 14, 2024 13:01
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.

2 participants