Skip to the content

Lesson 18 of 21 · Targets

One source, each target

The same files build a web app and a native app. surf build writes the web app, and surf build --target desktop writes a binary for this computer. surf build --target server writes a server for an app with routes.The web, macOS, Linux and Windows work now. iOS and Android come after version 1.Platform.os is a constant of the build. The compiler removes the code of the other targets in if Platform.os == .web { ... }, and it checks that code for each target too. A platform prefix applies a utility on some targets only: desktop:hidden, web:p-4.Your turn
  • Add this line above the ---:
  • derived place = Platform.os == .web ? "a browser" : "a native window";
  • Change the second Text to This app runs in {place}.
  • Add a Text with style="desktop:hidden". A desktop build removes it from the layout.
Preview
1 error
The sandbox needs a browser.