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

Enhancement: move JS dependencies to package.json #1141

Open
kinow opened this issue Mar 20, 2021 · 0 comments
Open

Enhancement: move JS dependencies to package.json #1141

kinow opened this issue Mar 20, 2021 · 0 comments
Labels
Milestone

Comments

@kinow
Copy link
Collaborator

kinow commented Mar 20, 2021

At the moment the dependencies of Skosmos are defined in Twig. The scripts are defined in a order that is important and may change how the code works.

We could move this to package.json file, which would enable tools like dependabot to scan our JS dependencies and alert about vulnerabilities (related to #1122).

This can also be used to invoke SASS/SCSS, allowing to improve our stylesheets too, and then producing a single bundle JS (related to #1045).

Furthermore, we could improve browser support via polyfills if necessary, or allow modern JS and transpile it down to ES5/ES6 with something like Babel + webpack.

This could allow us to also write tests with mocha/chai or jest, increasing the overall quality of the code and preventing regressions due to changes in JS.

And, finally, I think this helps to separate the PHP and JS code, which could be helpful if in the future we need/want to move to a framework like Angular/React/Vue/etc.

Implementation

I don't remember seeing a PHP project with the package.json to use as reference 😥 but I've seen Composer scripts for things like generating auth keys, re-creating cache, etc.

So I guess we could hook up one of the composer lifecycles (pre-package? post-package-install?) and call npm build. Then, in the package.json, the build script would run something like webpack ... that would bundle all the JS files (in the order necessary, maybe even doing some tree-shaking to reduce the final JS code size).

This would produce a file index.js (or skosmos.js, or any name we'd like) that would be the single import in scripts.twig. It could also generate the skosmos.css file, combining all the stylesheets (including bootstrap.min.css, again, in the right order, minified).

@kouralex kouralex added enhancement size-medium 2 hours to 2 days labels Mar 22, 2021
@kouralex kouralex added this to the Next Tasks milestone Mar 22, 2021
@osma osma modified the milestones: Next Tasks, 3.0 Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Proposed Skosmos 3.0 issues (to do)
Development

No branches or pull requests

3 participants