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

build: npm run build (experimental) #32823

Merged
merged 3 commits into from
Jul 26, 2023

Conversation

kdmccormick
Copy link
Member

@kdmccormick kdmccormick commented Jul 24, 2023

This PR implements much of: https://github.com/openedx/edx-platform/blob/master/docs/decisions/0017-reimplement-asset-processing.rst

This is backwards-compatible. paver update_assets should not be affected.

The new command warns that it is "experimental" for a few reasons:

  1. Currently, npm run build will fail in the webpack phase unless you first run xmodule_assets. This will be changed soon, so I did not feel that it would be worthwhile to add a separate special npm run xmodule-assets step.
  2. I have tested the new build, but not quite so thoroughly that I'd recommend it as the production default yet. In fact, once the xmodule_assets work lands, I'd like to share this on the forums so early adopters can try it out. That'll make me more comfortable making it the default over Paver.
  3. The commands lack some top-level documentation. Once they stabilize more, I'd like to add a section to the README that explains how and when to use npm run build, its subcommands (npm run webpack[-dev], npm run compile-sass[-dev]), and the environemnt variables (STATIC_ROOT_LMS, etc).
  4. npm run watch is not yet implemented. The current asset-watching that edx-platform and Tutor provide both rely on Paver.

Part of: #31604

Testing

There are a few different ways you could test this:

  • Directly from your host, preview the Sass help & output:

    npm run compile-sass -- --help
    npm run compile-sass -- --dry --theme-dir=themes`
  • Using Tutor Nightly dev:

    tutor mounts add path/to/edx-platform
    tutor dev run lms npm clean-install
    tutor dev run lms openedx-assets xmodule
    tutor dev run lms npm run build-dev
    tutor dev start -d
  • Using Tutor Nightly prod:

    tutor mounts add path/to/edx-platform
    tutor local run lms npm clean-install
    tutor local run lms openedx-assets xmodule
    tutor local run lms npm run build
    tutor local start -d
    tutor local exec lms ./manage.py lms collectstatic --noinput
    tutor local exec cms ./manage.py cms collectstatic --noinput
  • If you're adventurous: directly from your host, try:

    npm clean-install
    pip install -r requirements/edx/base.txt  # (would be assets.txt if not for xmodule_assets command)
    xmodule_assets common/static/xmodule
    npm run build-dev

Copy link
Member Author

@kdmccormick kdmccormick left a comment

Choose a reason for hiding this comment

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

Notes for reviewers 👀

package.json Outdated
Comment on lines 6 to 12
"postinstall": "scripts/copy-node-modules.sh",
"build": "echo 'WARNING: `npm run build` in edx-platform is experimenal. Use at your own risk.' && npm run webpack && npm run compile-sass",
"build-dev": "echo 'WARNING: `npm run build-dev` in edx-platform is experimenal. Use at your own risk.' && npm run webpack-dev && npm run compile-sass-dev",
"webpack": "NODE_ENV=${NODE_ENV:-production} \"$(npm bin)/webpack\" --progress --config=${WEBPACK_CONFIG_PATH:-webpack.prod.config.js}",
"webpack-dev": "NODE_ENV=development \"$(npm bin)/webpack\" --progress --config=webpack.dev.config.js",
"compile-sass": "scripts/compile_sass.py --env=${NODE_ENV:-production}",
"compile-sass-dev": "scripts/compile_sass.py --env=development"
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'd love to add comments here, but I can't since it's JSON. I do plan to document these in edx-platform's README, though, once they stabilize more.

In short:

  • npm run webpack is a super thin wrapper around webpack.
  • npm run compile-sass calls a script (currently written in Python, maybe one day written in Bash) which compiles Sass into CSS.
  • npm run build is a combination of the above.
  • The -dev targets are just simple variations of the base commands, for the convenience of developres.
  • Wherever it was possible, I've written these so that:
    • You can override them with en vars, eg WEBPACK_CONFIG_PATH=my-special-config.js npm run webpack
    • You can provide extra options: npm run compile-sass -- --theme-dir=/my/cool/themes

libsass==0.10.0 # Python bindings for the LibSass CSS compiler
libsass # Python bindings for the LibSass CSS compiler
Copy link
Member Author

Choose a reason for hiding this comment

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

Constraint is moved over to constraints.txt so that it can be shared by assets.txt.

"theme_dirs",
metavar="PATH",
multiple=True,
envvar="EDX_PLATFORM_THEME_DIRS",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a new env var, and is mentioned in the ADR. Eventually, I will document it in the edx-platform README.

Comment on lines +29 to +30
var staticRootLms = process.env.STATIC_ROOT_LMS || "./test_root/staticfiles";
var staticRootCms = process.env.STATIC_ROOT_CMS || (staticRootLms + "/studio");
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 goal of all the changes in this file is to provide some reasonable defaults for all env vars, so that webpack can be run on its own without having to supply a pile of environment variables.

We could have shoved all these defaults into the npm run webpack call in package.json, but that seemed worse than putting them here.

@kdmccormick kdmccormick marked this pull request as ready for review July 24, 2023 15:25
@kdmccormick kdmccormick requested a review from feanil July 24, 2023 15:27
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

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

I tried to run this after running make clean in edx-platform.

npm install --legacy-peer-deps
npm run build

I got the following error:

Error: Cannot find module './common/static/xmodule/webpack.xmodule.config.js'

Did a file not get checked in or did I miss a step somewhere?

@kdmccormick
Copy link
Member Author

@feanil Yep, you missed the xmodule_assets common/static/xmodule, which will be necessary until we merge #32685.

Copy link
Contributor

@feanil feanil left a comment

Choose a reason for hiding this comment

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

Ah, doh, missed the bottom of the description. But yes that was it, it works now, I was able to get all the assets built locally without any issue.

@kdmccormick kdmccormick merged commit 3e67719 into openedx:master Jul 26, 2023
41 checks passed
@kdmccormick kdmccormick deleted the kdmccormick/npm-run-build branch July 26, 2023 12:04
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

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.

3 participants