shaack / cm-chessboard

A JavaScript chessboard without dependencies. Rendered in SVG, coded in ES6. Views FEN, handles move input, animated, responsive, expandable
MIT License
209 stars 63 forks source link

Issue/137 add entry point index js #138

Closed programarivm closed 2 weeks ago

programarivm commented 4 months ago

All examples have been tested using the new entry point and now some are importing cm-chessboard files from index.js. Closes https://github.com/shaack/cm-chessboard/issues/137

programarivm commented 4 months ago

Also by the way the package.json file could be updated as shown in chesslablab/cmblab in order to define the primary entry point of the library.

...

  "module": "./src/index.js",
  "browser": "./src/index.js",

...

However, if doing so I'm not too sure about how this would be backward-compatible with previous versions.

import {
  Chessboard,
  BORDER_TYPE,
  FEN
} from 'shaack/cm-chessboard'
shaack commented 4 months ago

I understand that this is your style of doing imports, but I prefer importing from the original files. Maybe because I am from Java and want to keep it simple. For importing the classes from node_modules or somewhere else, I use importmap. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap

<script type="importmap">
    {
        "imports": {
            "cm-chessboard/": "./node_modules/cm-chessboard/"
        }
    }
</script>

With defining the module path in importmap (like above) you can import like this

import {Chessboard, COLOR, INPUT_EVENT_TYPE} from "cm-chessboard/src/Chessboard.js"

What is the reason that you want to put everything in an index.js? This file must also be maintained for changes such as refactoring.

programarivm commented 4 months ago

See https://github.com/shaack/cm-chessboard/issues/137#issuecomment-1986870864

shaack commented 2 weeks ago

Sorry, I only add things which must be maintained, if it is useful for my projects, mainly https://chessmail.de But anyway thank you for the thoughts on optimizing cm-chessboard. 👍