Skip to content

Angular 13 compatibility (and other frameworks/bundlers) #269

@tajnymag

Description

@tajnymag

At the moment, the library is published only in its amd, umd and cjs form. Would it be possible to also provide the unbundled esm format? Possibly also combined with specifying the exports (docs) field in package.json to make consuming bundlers aware of the available library formats.

We are trying to use the components in an Angular 13 project so far without any luck. The provided shell template helps only a little, as it heavily relies either on old, custom or heavily configured tooling.

However, with some modifications, we were able to make the package work. Here are the changes:

package.json#exports

We added the exports field to package.json. This allowed the angular compiler to import the correct compiled library.

"exports": {
        ".": {
            "import": "./build_bundles/lib-esm/index.js",
            "require": "./build_bundles/amd/index.js",
            "node": "./build_bundles/cjs/index.js",
            "default": "./build_bundles/umd/index.js"
        },
        "./esm": {
            "import": "./build_bundles/lib-esm/index.js",
            "types": "./build_bundles/lib-esm/index.d.ts"
        },
        "./umd": {
            "default": "./build_bundles/umd/index.js",
            "types": "./build_bundles/umd/index.d.ts"
        },
        "./cjs": {
            "node": "./build_bundles/cjs/index.js",
            "types": "./build_bundles/cjs/index.d.ts"
        },
        "./amd": {
            "require": "./build_bundles/amd/index.js",
            "types": "./build_bundles/amd/index.d.ts"
        }
    },

tsconfig.esm.json

npm build:dev:esm didn't seem to do anything. No errors and no artifacts created. We solved it by specifying files property in tsconfig.esm.json. There is probably a better way to solve this.

"include": ["**/*.ts"]

Usage of process.env

CH5ComponentLibrary relies on webpack to replace process.env used in the source files. This doesn't work for the esm build which are built with tsc only. Without further modifying the library, we opted to polyfill window.process.env in the global scope of our app.

<script>
  window['process'] = {
    env: {
      BUILD_VERSION: "1.0.0",
      BUILD_DATE: "2019-01-01",
    }
  }
  </script>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions