impress-org / givewp

GiveWP - The #1 Donation Plugin for WordPress. Easily accept donations and fundraise using your WordPress website.
https://givewp.com/
GNU General Public License v3.0
344 stars 191 forks source link

Update JS with ES6 standard code #339

Closed DevinWalker closed 6 years ago

DevinWalker commented 9 years ago

Issue Overview

Modernizing our JS is important to ensure we're up to date with current standards and

Future Stack

Questions:

kevinwhoffman commented 6 years ago

Here's my recommended plan for transitioning from Gulp to webpack and cleaning up our asset pipeline along the way.

Stack

You can see an example of this stack in the WP Business Reviews repository.

Phase 1

Phase 1 includes high-level front-end architecture changes. We're setting up the directory structure and pipeline, but we're not worried about refactoring individual assets.

  1. Audit existing assets to see if scripts/styles can be broken down better. For example, do all front-end scripts need to be in one file, or can they be broken up?
  2. Introduce webpack.config.js to replace gulpfile.js
  3. Split the assets directory into assets/src and assets/dist.
    • assets/src
      • js - Source JS modules
      • css - Sass partials
      • images - Source images
      • fonts - Fonts
    • assets/dist
      • js - Compiled/minified/concatenated JS
      • css - Preprocessed/minified/concatenated CSS
      • images - Minified images
      • fonts - Fonts
  4. Ignore the dist directory which will remove minified assets from version control. Instead build the directory using an npm script.
  5. Update the WordPress enqueue calls to use the new directory structure.

Phase 2

Phase 2 includes refactoring of individual assets to a more modern, class-based architecture made possible by ES6 and webpack. Most of Give's JS assets are currently a collection of expressions that work together without much structure. Furthermore a function in one file cannot be easily used in another file due to every file having its own scope.

If we instead write JS as classes and import them as modules throughout the Give asset pipeline, then we can start to treat our JS as series of interdependent modules rather than a collection of independent files.

Benefits

Learning Materials

raftaar1191 commented 6 years ago

Move https://github.com/WordImpress/Give-Form-Field-Manager/pull/201/files#diff-a0b8932df51abf64f7457c93c4e403f2R3127 get_parameter to Give Core when we reform the Give Core JS

We also have a function related to this type In Give Admin JS https://github.com/WordImpress/Give/blob/release/2.0/assets/js/admin/admin-scripts.js#L2945 get_url_params

kevinwhoffman commented 6 years ago

Closing as Phase 1 of the webpack integration is complete in Give core 2.1.0. Phase 2 (refactoring existing code) can be addressed in smaller targeted issues.