Git Product home page Git Product logo

chartjs-esm-facade's Introduction

Chart.js ESM Flat Facade

NPM Package Github Actions

This is a helper package for the latest chart.js 3.0.0-alpha.2 version to provide a unified flat export hierarchy for both UMD and ESM cases. It is an application of the Facade Design Pattern.

Works only with Chart.js >= 3.0.0-alpha.2

Install

npm install --save chart.js@next @sgratzl/chartjs-esm-facade@next

Usage

ESM

import {
  Chart,
  CategoryScale,
  LinearScale,
  Rectangle,
  Legend,
  Line,
  merge,
  valueOrDefault,
} from '@sgratzl/chartjs-esm-facade';

UMD

const { Chart, CategoryScale, LinearScale, Rectangle, Legend, merge, valueOrDefault } = ChartESMFacade;

see Samples on Github

Library Usage

In order to proper choose the right adapter when embedding it into a library, one has to enforce the UMD case when building UMD package versions. This will be accomplished using an alias in the bundler.

An example rollup config

// rollup.config.js
import pnp from 'rollup-plugin-pnp-resolve';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import alias from '@rollup/plugin-alias';
import pkg from './package.json';

export default [
  {
    input: 'src/bundle.js',
    output: {
      file: pkg.main,
      name: 'UMDName',
      format: 'umd',
      globals: {
        'chart.js': 'Chart',
      },
    },
    external: ['chart.js'],
    plugins: [
      alias({
        // enforce UMD adapter version
        entries: [
          {
            find: /^(@sgratzl\/chartjs-esm-facade)$/,
            replacement: '@sgratzl/chartjs-esm-facade/src/index.umd.js',
          },
        ],
      }),
      commonjs(),
      pnp(),
      resolve(),
      babel({ babelHelpers: 'runtime' }),
    ],
  },
  {
    input: 'src/index.js',
    output: {
      file: pkg.module,
      format: 'esm',
    },
    external: (e) => e === 'chart.js' || e.startsWith('chart.js/'),
    plugins: [commonjs(), pnp(), resolve()],
  },
];

Development Environment

npm i -g yarn
yarn set version 2.1.0
yarn
yarn pnpify --sdk vscode

Building

yarn install
yarn build

chartjs-esm-facade's People

Contributors

sgratzl avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

jonrimmer

chartjs-esm-facade's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.