Page MenuHomePhabricator

Switch to a different frontend workflow: Bundle and precompile frontend assets
Closed, DeclinedPublic

Description

An alternative frontend workflow for extensions

This epic explains and proposes an alternative workflow for frontend development on extensions.

Explicit and mandatory goals of the workflow are:

  • Remain fully compatible with mediawiki core and ResourceLoader
  • Be an optional workflow that can be adopted per project or extension with front-end assets
  • Rely on widely used and maintained (only) open source leveraging the broader OSS community
  • Achieve the goals listed in the Goals section

A proof of concept implementation is provided for the isolated and small MediaWiki-extensions-Cards, see the How section. Out of scope are the reasons for existence of such extension, it is just used as test bed.

Why

  • Manual configuration of extension.json ResourceModules ends up being big, very complex and error prone (ex. 1700 lines on MobileFrontend). Hard to modify, optimize, and it has caused non-deterministic JS exceptions due to misconfigurations (ex. T146031 T145566 T99461).
  • Slow, integrated (requiring mediawiki install) unit tests, that are not real unit tests discourage testing practices and coverage.
  • Inability to consume and integrate libraries from npm into our source code.
  • Inability to use frontend tools from the npm ecosystem.
  • Inability to have source maps on production code to diagnose problems.
  • Bigger than necessary frontend bundles served to clients due to out of date minifier on the bundle
  • Performance hit of having to compile templates on clients

Goals

  • Reduce manual configuration of dependencies of modules to avoid misconfiguration and non-deterministic JS failures
  • Enable the possibility of consuming JS libraries from npm
  • Precompile templates instead of sending a compiler and text templates and compiling them in client browsers
  • Minimize size of front-end assets sent to the client by using up to date tools like uglify
  • Have source-maps mapping to the original sources both in development and production
  • Being able to run front-end unit tests fast and quickly in a node environment, and enable the possibility of doing TDD while developing

What

Use a node based asset bundler to realize the frontend dependency graph and bundle it, instead of relying on manual configuration in a JSON file.

Main choices because of usage and support are browserify and webpack. Both being good choices, webpack has been chosen because of it's batteries-included approach.

How

Post-implementation work

  • Enumerate bundle sizes pre-post migration, configuration simplification, test workflow improvements
  • Create epic for folding cards work and workflow into related-articles extension.

Event Timeline

Change 312508 had a related patch set uploaded (by Phuedx):
Bundle templates

https://gerrit.wikimedia.org/r/312508

Change 312509 had a related patch set uploaded (by Phuedx):
Bundle CSS.escape library

https://gerrit.wikimedia.org/r/312509

Change 312821 had a related patch set uploaded (by Phuedx):
Run CardModel unit tests in Node.js

https://gerrit.wikimedia.org/r/312821

Change 312499 had a related patch set uploaded (by Phuedx):
Use webpack to bundle assets

https://gerrit.wikimedia.org/r/312499

Change 312822 had a related patch set uploaded (by Phuedx):
Run CardView unit test in Node.js

https://gerrit.wikimedia.org/r/312822

Change 313975 had a related patch set uploaded (by Phuedx):
Add npm script to check built assets on npm test

https://gerrit.wikimedia.org/r/313975

Change 314245 had a related patch set uploaded (by Phuedx):
Generate source maps

https://gerrit.wikimedia.org/r/314245

Jhernandez renamed this task from Bundle and precompile frontend assets to Switch to a different frontend workflow: Bundle and precompile frontend assets.Oct 5 2016, 4:13 PM
Jhernandez updated the task description. (Show Details)
jhobs triaged this task as Medium priority.Oct 5 2016, 5:13 PM
jhobs moved this task from Incoming to Epics/Goals on the Web-Team-Backlog board.

Change 312499 abandoned by Phuedx:
Use webpack to bundle assets

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/312499

Change 313975 abandoned by Phuedx:
Add npm script to check built assets on npm test

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/313975

Change 312508 abandoned by Phuedx:
Bundle templates

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/312508

Change 312509 abandoned by Phuedx:
Bundle CSS.escape library

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/312509

Change 312821 abandoned by Phuedx:
Run CardModel unit tests in Node.js

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/312821

Change 312822 abandoned by Phuedx:
Run CardView unit test in Node.js

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/312822

Change 314245 abandoned by Phuedx:
Generate source maps

Reason:
T147297 has since been updated.

https://gerrit.wikimedia.org/r/314245

Declined until we have a use case for it. Apparently Cards is not it.