Skip to content

ESM support for all Yivi packages #15

Open
@ericfennis

Description

We tried to use these frontend packages with our frontend using Vite.
But we have some problems with building, because of the lack of ESM support.
We currently have a workaround but it is not great.

I noticed in all the packages the require() imports are used, which is not very future-proof since most new frontend builders and javascript community already shifted to the import syntax. Also using the ECMA script is recommended by all build tools, see webpack documentation

Is it possible to switch to ECMA Script syntax or maybe even typescript.

Here is a nice blog article about publishing modern NPM package: https://snyk.io/blog/best-practices-create-modern-npm-package/

// /yivi-frontend/index.js
- require('@privacybydesign/yivi-css');
+ import '@privacybydesign/yivi-css';

- const YiviCore = require('@privacybydesign/yivi-core');
- const YiviWeb = require('@privacybydesign/yivi-web');
- const YiviPopup = require('@privacybydesign/yivi-popup');
- const YiviClient = require('@privacybydesign/yivi-client');
+ import YiviCore from '@privacybydesign/yivi-core';
+ import YiviWeb from '@privacybydesign/yivi-web';
+ import YiviPopup from '@privacybydesign/yivi-popup';
+ import YiviClient from '@privacybydesign/yivi-client';

module.exports = {
  newWeb: (options) => {
    const core = new YiviCore(options);
    core.use(YiviWeb);
    core.use(YiviClient);
    return {
      start: core.start.bind(core),
      abort: core.abort.bind(core),
    };
  },

  newPopup: (options) => {
    const core = new YiviCore(options);
    core.use(YiviPopup);
    core.use(YiviClient);
    return {
      start: core.start.bind(core),
      abort: core.abort.bind(core),
    };
  },
};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions