When developing an extension, you can sideload it from your local development machine's Parcel dev server (instead of re-publishing it after each code change). This speeds up the development cycle and avoids breaking the published version of your extension. This works on Sourcegraph.com and self-hosted instances.
To set this up:
- In your extension's directory, run
npm run serve
to run the Parcel dev server. Wait until it reports that it's listening. - Reveal the Ext ▲ debug menu by running the following JavaScript code in your browser's devtools console on a Sourcegraph page:
localStorage.debug=true;location.reload()
. - In the Ext ▲ debug menu, click Sideload Extension -> Load Extension.
- Enter the URL the Parcel dev server is listening on.
- Your extension should appear in the debug menu's "active extensions" list. If it doesn't, there may have been an error when activating your extension - check the debug console for error messages.
After doing this, the development cycle is as follows:
- Make a change to your extension's code, then save the file.
- Reload your browser window. (It will fetch the package.json and the newly compiled JavaScript bundle for your extension.)
When you're done, clear the sideload URL from the extensions debug menu.
Note: This workflow assumes that, when running the Parcel dev server, a symlink exists in the dist/
directory pointing to your package.json
. If you created your extension the easy way, this is already set up for you. Otherwise, follow these steps:
-
Add
mkdirp
andlnfs-cli
as dependencies (npm install --save-dev mkdirp lnfs-cli
). -
Add the following npm script to your
package.json
:"symlink-package": "mkdirp dist && lnfs ./package.json ./dist/package.json"
-
Edit the
serve
npm script to runsymlink-package
:"serve": "npm run symlink-package && parcel serve --no-hmr --out-file dist/your-extension.js src/your-extension.ts"