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

Replace Browserify with Rollup #3221

Merged
merged 4 commits into from
Oct 18, 2021
Merged

Replace Browserify with Rollup #3221

merged 4 commits into from
Oct 18, 2021

Conversation

robertknight
Copy link
Member

Change the LMS frontend to use Rollup for bundling JS. This change was done for the same reasons and using a similar approach to the corresponding change in the Hypothesis client. See hypothesis/client#3810.

As part of the bundling change, I found it necessary to wrap the initialization code for the frontend app in frontend_apps/index.js in a function. See the first commit for details.

Unlike in client hypothesis/client#3810, the bundles are still generated as classic scripts using an IIFE rather than native ES modules. This is because I think it will be easier to make that change in a separate step in this project.

@@ -1,22 +1,22 @@
'use strict';

/* eslint-env node */
/* eslint-disable no-var, prefer-arrow-callback */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I converted the remaining vars to consts and anonymous functions to arrow functions for consistency.

entry: './lms/static/scripts/ui-playground/index.js',
},
];
async function buildJS(rollupConfig) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buildJS, watchJS and buildAndRunTests functions are the same as the gulpfile.js in the client in hypothesis/client#3810, with just changes to the file paths. It might make sense to extract them into a package in future.

@@ -19,61 +19,65 @@ import { registerIcons } from '@hypothesis/frontend-shared';
import iconSet from './icons';
registerIcons(iconSet);

// Read configuration embedded into page by backend.
const config = readConfig();
function init() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in this module is just to extract all the code that was at the top level into an init function. In the context of this PR it avoids a warning from Rollup in development builds. In future it will also facilitate writing unit or integration tests of this module.

@robertknight
Copy link
Member Author

The backend tests are failing due to an issue with pip. That should be fixed with https://github.com/hypothesis/tox-pip-sync/pull/20.

This avoids a warning from Rollup in development due to Babel's JSX
transform generating references to `this` outside of a function/method.

It will also enable us to invoke the code with mocks in a test
environment in future. The browser extension uses a similar pattern.
Change the LMS frontend to use Rollup for bundling JS. This change was
done for the same reasons and using a similar approach to the
corresponding change in the Hypothesis client. See
hypothesis/client#3810.
@robertknight
Copy link
Member Author

robertknight commented Oct 15, 2021

I found a method to avoid the Node deprecation warning and slightly speed up loading of configs which we might want to apply here too. See hypothesis/client#3840. Will take a look at this next week.

Convert Rollup configs to native ES modules and load them with
`import(...)`. This avoids a deprecation warning from Node triggered by
the `loadConfigFile` import.

See also hypothesis/client#3840
@robertknight
Copy link
Member Author

This PR has been updated to match the changes in hypothesis/client#3840, which avoids the Node deprecation warning.

robertknight added a commit to hypothesis/frontend-shared that referenced this pull request Oct 18, 2021
Change bundling in development and when running tests to use Browserify
rather than Rollup. This adapts the changes that were recently made in
the lms [1] and client [2] projects.

[1] hypothesis/lms#3221
[2] hypothesis/client#3840

This follows the pattern and reuses code from the re
robertknight added a commit to hypothesis/frontend-shared that referenced this pull request Oct 18, 2021
Change bundling in development and when running tests to use Browserify
rather than Rollup. This adapts the changes that were recently made in
the lms [1] and client [2] projects.

[1] hypothesis/lms#3221
[2] hypothesis/client#3840
Copy link
Contributor

@lyzadanger lyzadanger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look consistent with those in other projects. I have verified that I am able to make dev and run tests. Let me know if there's anything else you'd like me to poke at!

robertknight added a commit to hypothesis/frontend-shared that referenced this pull request Oct 18, 2021
Change bundling in development and when running tests to use Rollup
rather than Browserify. This adapts the changes that were recently made in
the lms [1] and client [2] projects.

[1] hypothesis/lms#3221
[2] hypothesis/client#3840
@robertknight robertknight merged commit 7de87a2 into master Oct 18, 2021
@robertknight robertknight deleted the rollup branch October 18, 2021 14:08
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.

2 participants