Supporting frontend build in Motoko playground

We are happy to roll out an experimental feature to build frontend code in Motoko playground.

To get started, you can try the “counter” and “random maze” examples, which have been preloaded with the frontend code from the dfinity/examples repo.

You first need to deploy the backend as usual. Then select any file in the frontend project folder, the deploy button will change to “Deploy Frontend”, which runs npm behind the scenes to build the whole frontend project. The reason we need to deploy in two steps is that the frontend needs to know the backend canister id at the build time, so we need to deploy the backend first.

When deploying the frontend, you may notice an interesting fact that we are running npm inside your browser, and the “node_modules” directory is only a virtual link that never gets downloaded. As a result, “npm install” is even faster than running in your native environment.

All these features are made possible by using the WebContainer technology, which can host node runtime (as well as python runtime) in browser as Wasm modules. As this technology is relatively new, not all browsers support it. It can run in most Chromium based browsers (Chrome, Edge, Opera, Brave, etc), and has limited support in Firefox and Safari. You can see this article on how to configure your browser to enable WebContainer. If you are using a non-supported browser, we simply disable the frontend build feature, and you can continue to deploy Motoko backend in the browser as usual.

You may also notice that we recently announced a similar product ICP Ninja that can deploy full stack dapps in browser as well. Both products share the same backend deployment infrastructure. While Motoko playground aims at supporting Motoko dapps, including the frontend as we rolled out in this feature, ICP Ninja is aimed at supporting all CDKs, including Motoko, Rust, Azle and Kybra.

Because of the scope difference, the build pipeline is different: Motoko playground builds everything in browser, which means the build pipeline is fully on-chain; while Ninja builds the projects in a docker service, since Rust is difficult to build in browser at the moment. These differences are just implementation details and not visible to the end users. We do expect that most people will use Ninja when it’s fully developed.

On the other hand, Motoko playground will truly become a playground, where we explore various features, e,g., different GC flags, the upcoming Motoko enhanced orthogonal persistence feature and profiling. As two products share most of the code, we can easily push the features to Ninja whenever it makes sense.

One of the experimental features we would like to try is building frontend with WebContainer, as we described in this post. WebContainer simplifies a lot of the scalability and security issues raised when using dockers like in ICP Ninja. It’s also nice to have a fully on-chain solution to build full stack dapps. However, because it’s a relatively new technology, it’s still not fully supported in all browsers, especially in mobile. ICP Ninja would have to wait a bit before getting this feature.

Hope you enjoy the new feature and keep on building! We are always here to hear your feedback.

6 Likes

Amazing piece of cutting edge front-end tech.
Have you considered using the web version of VScode instead of making the UI yourselves?
[https://vscode.dev/]

1 Like

For ICP Ninja we looked at 20+ different products before begrudgingly deciding to build our own. Most products are geared at authenticated dev environments with full console access (in our scenario that means “with remote code execution exploit as a feature”). Products that don’t offer a CLI are not extensible enough. And the VSCode stuff that we could maybe have used has a license that forbids us from using it. The issue with vscode.dev specifically is that it isn’t even open source so there’s no way we could adapt it for our use case

In the official Vscode git there are scripts that launch the same IDE locally like what you see at vscode.dev .
image
The repo says MIT + some proprietary components, but hard to tell which are these.

And it gets more complicated. From the FAQ:

Can I host the VS Code Server as a service?
No, hosting it as a service is not allowed, as specified in the VS Code Server license.

Then it also says

Is the VS Code Server designed for multiple users to access the same remote instance?
No, an instance of the server is designed to be accessed by a single user.

Which means that even if we could use the server then it wouldn’t really fit our use case. We’d prefer not having to run a full backend for every concurrent user. And only running a customized frontend as vscode.dev does it also looks pretty hard. Then we’re at least close to if already past the difficulty of building our own entirely

This is very cool. Has the importing of git repos improved? I remember having some issues and it being pretty strict about how a project had to be setup.

Also, Mops integration would be very nice. :slight_smile:

I love that the motoko tools are getting this attention. Keep it up!

One cool feature for the motoko VS plugin might be to have a ‘launch this workspace in Motoko Playground’. If all the items are in github it could just send them in a list to the playground and set it all up for you. :slight_smile: @rvanasa

2 Likes

Has the importing of git repos improved? I remember having some issues and it being pretty strict about how a project had to be setup.

I don’t remember we have restrictions on git imports. If you have an example, I will look into it.

Also, Mops integration would be very nice. :slight_smile:

ICP Ninja already supports mops.toml. It’s on my todo list to support mops in the playground as well. We can even auto-generate mops.toml from the motoko source code if all the imports are from mops.

What’s the point of supporting both projects, i.e Playground and ICP.ninja. Wouldn’t it make more sense to merge them into a single product?

@Zane , straight to the point!

This is definitely a topic that we’ve discussed internally. The grand plan is to continue to invest into ICP Ninja and make it a feature rich free online IDE for ICP with a focus on the learning experience. There are a few features that we need to implement before Motoko Playground can be sunset. Meanwhile, we have started updating the ICP documentation and adding references to ICP Ninja (to be published soon).

Stay tuned for the December release of ICP Ninja!

1 Like