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

feat!: major folder restructuring with esbuild to support iife, cjs and esm and TypeScript #804

Merged
merged 124 commits into from
Jul 13, 2023

Conversation

ghiscoding
Copy link
Collaborator

@ghiscoding ghiscoding commented Jun 30, 2023

  • add esbuild as our main bundler, with esbuild we now have 3 different builds in the dist folder
    • iife which is the same as the start of SlickGrid years ago, the only difference will be the located under dist/browser
    • cjs for CommonJS build for NodeJS legacy loading using require(...), located under dist/cjs
    • esm for ES6/ESM support which will give us Tree Shaking support (located under dist/esm)

I did a lot of research to make sure that we get the smallest possible builds for each build format types, for example I didn't want to have code that isn't used by the iife format but required for esm and vice versa (i.e. import are used by esm but not used at all in iife). It took me a while to find the best approach, I even asked on SO with this question: esbuild hybrid plugin to bundle multiple files iife and single esm bundle and opened an issue on esbuild as well. Eventually made it all work with the smallest build sizes for all build types, woohoo 🚀

Starting with the iife build (located under the dist/browser folder) we will still build individual files and we are still adding everything on the Slick object on window (i.e. Slick.Grid or window.Slick.Grid)

On the other hand, the cjs and esm are both producing a single index.js bundle and the esm will provide us with Tree Shaking support. As opposed to iffe though, there will not be any Slick object produced, the user will have to import (or require) everything, for example with esm we would do import { SlickGrid } from 'slickgrid'; and that is the common approach for ES6 syntax

Installation

  1. npm install to install all new dev dependencies (esbuild and others...)
  2. npm run dev for development using Browser-Sync and build for dev mode
    • this will open a new browser page, the index.html was updated will all the Example links (which contains the same as the Examples Wiki)
    • also note that the ESM examples will only work through this dev mode, however the non-iife examples can still be run without the http server as long you had originally ran a build

Then finally, and hopefully, be amazed by the new Alpine Theme look and feel... Beautiful, isn't it? 🐰

Note ESM examples will only work when running the http server (with npm run dev), on the other hand the regular examples can still be run independently by opening file in the browser but you will be required to first run a build, so... technically speaking it's mostly easier to just run npm run dev for everything (this brings a watch mode which is a lot more useful).

Info

The new structure will use a lot more new tools for development like:

  • esbuild to build and bundle, it takes anything from JavaScript and even TypeScript and produces JS build
  • chokidar to watch for file changes (.ts, .js, .css, .scss and .html) and run appropriate process (i.e.: .scss will run a SASS build, .ts would run an esbuild, ...)
  • browser-sync to run an http server & also watch for any html file change, if anything changes the browser-sync will automatically reload the opened web page (also reloads on any file change).

The use of Browser-Sync is awesome because we no longer need to refresh the page, whenever a file changes (js, css or html), the watch mode will simply reload the page by itself, awesome! The use of Chokidar in combo with Browser-Sync is also great since it will also rebuild SASS to CSS and reload the page as well if anything changes.

This PR branch was created about 2 months ago so it contains a lot of old commits (including the previous major version) but I feel now is a good time to merge it into a new next branch and get feedback from others. I say this because at this point, I feel like the folder structure is pretty much what I want it to become at the end of this exercise.

Upcoming TypeScript

Like I mentioned earlier, we can use esbuild since it accepts TypeScript (and JavaScript) and it's super fast to build. When we run our final production build, we will also use TypeScript to create all the Types (d.ts) files and source maps.

I already converted 1 of the plugin, it is the smallest one which is good to start with and that is the SlickAutoTooltips and it is also part of this PR. So yes, TypeScript is coming...🤖

This next major version will eventually close some old issues as well

Conclusion

So in conclusion, I encourage anyone to give it a try. Also note that this PR will be merged on the next branch and a few more PRs will follow (like TypeScript migrations). At this point the folder structure is not expected to change much more than what is in this PR, however all the .js will be renamed as .ts files. Please note that all images were deleted, it's all SVGs now and in pure CSS, so we can even easily colorize them, SVGs are not just used by the new Alpine Theme but also referenced by the old SlickGrid theme which I updated as well in order to get rid of images. This new Alpine Theme was based and inspired from Ag-Grid.

To see the new folder structure, you can take a look at the feat/esbuild branch directly

EDIT

I managed to migrate slick.grid and even slick.dataview to TypeScript (that took a week to accomplish) and that was the biggest challenge, so the rest of the files should be easy (all Controls and Plugins). There's no more obstacle for the move to TypeScript :)

MarkoBL and others added 30 commits April 28, 2023 20:49
* feat!: Drop jQuery requirement
)

- fixes some errors that came up while testing the whole thing in Slickgrid-Universal
- fix ESLint for Cypress
- also remove jQuery from package.json list of dependencies
#740 (#741)

* show tooltip if the cell content is taller than the cell height

The current code does not show a tooltip when word wrap is turned on and the text is taller than the cell height.

* combined height check with width check
 (#736)

* fix: enable AutoScroll with SortableJS for column reordering, fixes #735

* chore: add auto-scroll comment for clarity
- remove jQuery from plugin and also in the autotooltip example as well
* chore: apply better code styling to few core files
)

* feat(plugins): remove jQuery from ColumnPicker & GridMenu controls

* tests: use input checked property instead of attr checked
- the previous code with `attr('checked')` was jQuery oriented and we are going away from jQuery
* feat(plugins): remove jQuery from range decorator selection model
- Slick.Map polyfill is no longer required since Map is included in ES6 browsers
@ghiscoding ghiscoding changed the title feat!: major folder restructuring with esbuild to support iife, cjs and esm and soon TypeScript WIP - feat!: major folder restructuring with esbuild to support iife, cjs and esm and soon TypeScript Jul 10, 2023
@ghiscoding ghiscoding changed the title WIP - feat!: major folder restructuring with esbuild to support iife, cjs and esm and soon TypeScript feat!: major folder restructuring with esbuild to support iife, cjs and esm and soon TypeScript Jul 13, 2023
@ghiscoding
Copy link
Collaborator Author

ghiscoding commented Jul 13, 2023

@6pac I'm going to merge this PR to next branch since it's already starting to be quite large. All the core files were converted to TypeScript, the next step will be to convert all Controls & Plugins in future PRs into the next branch.

This way you can start testing and toying with the new structure and you could start creating PR against it (on the next branch), for example your open PR #805

@ghiscoding ghiscoding merged commit fc57b5e into next Jul 13, 2023
@ghiscoding ghiscoding deleted the feat/esbuild branch July 13, 2023 04:59
@ghiscoding ghiscoding changed the title feat!: major folder restructuring with esbuild to support iife, cjs and esm and soon TypeScript feat!: major folder restructuring with esbuild to support iife, cjs and esm and TypeScript Jul 13, 2023
ghiscoding added a commit that referenced this pull request Sep 19, 2023
* feat!: major folder restructuring with esbuild to support `iife`, `cjs` and `esm` and soon TypeScript (#804)

* feat: migrate all Controls to TypeScript (#808)

* feat: migrate all Menu/Buttons Plugins to TypeScript (#811)

* feat: migrate all Decorator & Selection Plugins to TypeScript (#812)

* feat: migrate CheckboxSelector & State Plugins to TypeScript (#813)

* feat: migrate Draggable Grouping Plugins to TypeScript (#814)

* feat: migrate Resizer Plugin to TypeScript (#815)

* feat: migrate RowMoveManager Plugins to TypeScript (#817)

* feat: migrate RowDetail Plugin to TypeScript (#822)

* feat: migrate RemoteModel Plugins to TypeScript (#823)

* feat: remove deprecated DataView methods (#833)

* feat: remove deprecated DataView methods
- `setAggregators` and `groupBy` were both replaced by `setGrouping` many years ago, so no need to keep these old functions anymore

* feat: add new trading platform high frequency update grid (#835)

* feat: add new trading platform high frequency update grid

* fix: copying multiple times only kept last undo CellExternalCopyManager
- fix an issue where copying and pasting to multiple area only kept the last undo and reapplied it over and over and the cause was because the clipCommand was global to the class so it only kept the last undo, the fix is to make sure the clipCommand variable is local to the execution handler instead

---------

Co-authored-by: Nikhil Giddaluru <38428547+nikhil5693@users.noreply.github.com>
Co-authored-by: Ben McIntyre <email.ben.mcintyre@gmail.com>
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.

4 participants