Ignite Microsoft has hinted that cross-platform development framework React Native is a key solution to the problem of writing applications that span both Windows and mobile.
React Native for Windows + macOS brings React Native support for the Windows 10 SDK as well as the macOS 10.12 SDK. With this, you can use Javascript to build native Windows apps for all devices supported by Windows 10 including PCs, tablets, 2-in-1s, Xbox, Mixed reality devices, etc., as well as the macOS desktop and laptop ecosystems. Also as a web engineer, I wrote a simple SPA website for one of those apps I built above using React. I also wrote a Sketch plugin using Objective-C and accessibility API of macOS. Show more Show less. The great thing about React Native is, unlike Ionic/Cordova, it does not create webview based apps. Instead, it creates native components for the apps, so the performance of React Native apps is much greater than Ionic apps. By definition, Redux is a predictable state container for JavaScript apps. Tutorial Solutions Solutions to challenges mentioned at the end of React tutorial; Complete Apps. Hacker News Clone React/GraphQL Hacker News clone rewritten with universal JavaScript, using React and GraphQL; Builder Book Open-source web app to write and host documentation or sell books. Built with React, Material-UI, Next, Express, Mongoose. Nov 15, 2018 Building react-native apps for IOS. Running React Native for iOS doesn’t look much different from Android. The same React Native app that runs in Android can run on iOS as well, with some exceptions. For example if you want to run on an iOS device, you need to have a MacOS.
Cross-platform development is critical for Microsoft since both first-party and third-party apps accessing Office 365 or Azure services need to run on iOS and Android as well as on Windows. Underlining the point, the company has announced Surface Duo, a dual-screen Android device expected towards the end of next year.
In 2016 the company acquired Xamarin, enabling development for iOS, Android and macOS using C# and .NET. Microsoft has also invested in .NET Core, which runs on Windows, macOS and Linux.
Initially aimed at server development, .NET Core is evolving to support desktop Windows applications. Microsoft has also said that .NET 5 will be available in late 2020, and will 'target Windows, Linux, macOS, iOS, Android, tvOS, watchOS and WebAssembly and more'.
Despite all this activity, Microsoft is not depending entirely on .NET for cross-platform development. There are a couple of reasons for this. One is that the Windows team has historically been wary of .NET and the overhead of the Common Language Runtime (CLR), preferring to develop in C++ for performance reasons. WinUI, which is the next-generation API for Windows desktop applications, is built in C++. Second, the company is keen to appeal to developers beyond the .NET community, especially the huge number who are familiar with JavaScript and web technology.
Tangled in .NET: Will 5.0 really unify Microsoft's development stack?
READ MOREReact Native ticks all these boxes. The React web framework was developed by Facebook for building a user interface in JavaScript. In 2015 Facebook released React Native, which lets you use React for mobile applications for iOS and Android. React Native for Windows, sponsored by Microsoft, enables the framework to target Windows 10 UWP (Universal Windows Platform) or WPF (Windows Presentation Foundation) for Windows 7 and higher. The UWP version uses native WinUI controls. Developers can code in JavaScript or TypeScript, and tooling is provided for the popular Visual Studio Code editor.
UWP with C++ is best for performance, according to this slide from Microsoft
React Native for Windows generates .NET code, but this will be replaced with a C++ implementation in an upcoming release, currently called vNext. Presenting the plans at Ignite, Microsoft program managers Kalita Saintonge and Steven Moyes said that the vNext version, which should be production-ready by the end of 2019, reduces memory requirements and improves performance. They also noted that React Native is much leaner than the Electron framework, another cross-platform solution, because it does not require an embedded browser engine.
There are several clues concerning the importance Microsoft attaches to React Native. One is that it is already being used by the Office team. If you right-click in the latest Word, for example, and add a comment, the pop-up box that appears is written in React Native. So too is the forthcoming Office Calendar application, now in preview. These applications use the vNext implementation, rather than .NET.
'You might be thinking, could I use React Native to target the new [Surface] devices? The answer to that question is, we hope so,' said Moyes, showing a slide depicting Surface Duo. 'React Native is building native applications, it stands to reason that React is a great platform for building apps that target multiple platforms.'
Microsoft's official line is that Xamarin and React Native are equally good choices for targeting Windows and mobile, and that Xamarin is the sensible choice for those with existing C# code or skills, but it looks like React Native with C++ code generation is favoured by the Windows and Office teams for best performance.
What about Windows 7? This is an issue for business applications in companies that still use Windows 7, or for any Windows developer who wants the widest reach. You can do this in React Native using the WPF version, but Moyes was not keen. 'I believe we have a WPF component as well but most of our active investment is happening in the UWP layer. WPF… is more of a community module,' he told Ignite attendees. ®
Smashing Newsletter
Every second Tuesday, we send a newsletter with useful techniques on front-end and UX. Subscribe and get Smart Interface Design Checklists PDF in your inbox.
Technology makes our lives better, not just users, but also creators (developers and designers). In this article, I’ll introduce you to Tauri. This article will be useful to you if:
- you have been building applications on the web with HTML, CSS, and JavaScript, and you want to use the same technologies to create apps targeted at Windows, macOS, or Linux platforms;
- you are already building cross-platform desktop apps with technologies like Electron, and you want to check out alternatives;
- you want to build apps with web technologies for Linux distributions, such as PureOS;
- you are a Rust enthusiast, and you’d like to apply it to build native cross-platform applications.
We will look at how to build a native cross-platform application from an existing web project. Let’s get to it!
Note: This article assumes you are comfortable with HTML, CSS, JavaScript, and Vue.js.
What Is Tauri?
The official website sums up Tauri well:
- Tauri is a polyglot toolchain for building more secure native apps with both tiny and fast binaries. By “polyglot”, I mean that Tauri uses multiple programming languages. At the moment, Rust, JavaScript, and TypeScript are used. But there are plans to let you use Go, C++, Python, and more.
- It lets you use any HTML and JavaScript-based front-end framework, such as Vue.js, React, or Angular, to build a native desktop app, and it can be integrated into any pipeline.
- It helps you build and bundle binaries for major desktop platforms (mobile and WebAssembly coming soon).
So, basically, Tauri allows you to use web technologies to create tiny and secure native desktop apps.
On its GitHub page, Tauri is described as a framework-agnostic toolchain for building highly secure native apps that have tiny binaries (i.e. file size) and that are very fast (i.e. minimal RAM usage).
Why Not Electron?
A popular tool for using web technologies to build desktop applications is Electron.
However, Electron apps have a rather large bundle size, and they tend to take up a lot of memory when running. Here is how Tauri compares to Electron:
- Bundle
The size of a Tauri app can be less than 600 KB. - Memory
The footprint of a Tauri app is less than half the size of an Electron app. - Licence
Relicensing is possible with Tauri, but not with Electron. Electron ships with Chromium right out of the box. However, Chromium includes a digital rights-management system named Widevine. The inclusion of Widevine in Chromium makes apps created with Electron frowned upon by users of platforms such as PureOS for the sole reason that it is not free/libre open-source software (FLOSS). Platforms like PureOS are verified by the Free Software Foundation (FSF). This means that they can only publish free and open-source software in their app stores.
In a nutshell, if your app is built with Electron, it will never be shipped officially in the PureOS store. This should be a concern for developers targeting such distributions.
More Features Of Tauri
- Security is really important to the Tauri team. Apps created with Tauri are meant to be secure from the get-go.
- Tauri is compatible with any front-end framework, so you don’t have to change your stack.
- It has many design patterns to help you choose important features with simple configurations.
Pros Of Tauri
- Tauri enables you to take the code base you’ve built for the web and turn it into a native desktop app, without changing a thing.
- Although you could use Rust in a Tauri-based project, it is completely optional. If you did, you wouldn’t need to change anything in your original code base targeted for the web.
Real-World Tauri
If you have been part of the Vue.js community for a while, then you’ll have heard of Guillaume Chau, a member of the core team of Vue.js. He is responsible for the Vue.js command-line interface (CLI), as well as other awesome Vue.js libraries. He recently created guijs, which stands for “graphical user interface for JavaScript projects”. It is a Tauri-powered native desktop app to visually manage your JavaScript projects.
Guijs is an example of what is possible with Tauri, and the fact that a core member of the Vue.js team works on the app tells us that Tauri plays nicely with Vue.js (amongst other front-end frameworks). Check out the guijs repository on GitHub if you are interested. And, yes, it is open-source.
How Tauri Works
At a high level, Tauri uses Node.js to scaffold an HTML, CSS, and JavaScript rendering window as a user interface (UI), managed and bootstrapped by Rust. The product is a monolithic binary that can be distributed as common file types for Linux (deb/appimage), macOS (app/dmg), and Windows (exe/msi).
How Tauri Apps Are Made
Apps For Macos Using React To Work
A Tauri app is created via the following steps:
- First, make an interface in your GUI framework, and prepare the HTML, CSS, and JavaScript for consumption.
- The Tauri Node.js CLI takes it and rigs the Rust runner according to your configuration.
- In development mode, it creates a WebView window, with debugging and Hot Module Reloading.
- In build mode, it rigs the bundler and creates a final application according to your settings.
Setting Up Your Environment
Now that you know what Tauri is and how it works, let me walk you through setting up your machine for development with Tauri.
Note: The setup here is for Linux machines, but guides for macOS and for Windows are also available.
Linux Setup
The polyglot nature of Tauri means that it requires a number of tool dependencies. Let’s kick it off by installing some of the dependencies. Run the following:
Once the above is successful, proceed to install Node.js (if you don’t already have it), because Tauri requires its runtime. You can do so by running this:
This will install nvm (Node.js version manager), which allows you to easily manage the Node.js runtime and easily switch between versions of Node.js. After it is installed, run this to see a list of Node.js versions:
At the time of writing, the most recent version is 14.1.0. Install it like so:
Once Node.js is fully set up, you would need to install the Rust compiler and the Rust package manager: Cargo. The command below would install both:
After running this command, make sure that Cargo and Rust are in your $PATH
by running the following:
If everything has gone well, this should return a version number.
According to the Tauri documentation, make sure you are on the latest version by running the following command:
Voilà! You are one step closer to getting your machine 100% ready for Tauri. All that’s left now is to install the tauri-bundler
crate. It’s best to quit your CLI, and run the command below in a new CLI window:
Eureka! If everything went all right, your machine is now ready for Tauri. Next up, we will get started integrating Tauri with Vue.js. Let’s get to it!
Yarn
The Tauri team recommends installing the Yarn package manager. So let’s install it this way:
Then run the following:
If everything worked, a version number should have been returned.
Integrating Tauri With Vue.js
Now that we have Tauri installed, let’s bundle an existing web project. You can find the live demo of the project on Netlify. Go ahead and fork the repository, which will serve as a shell. After forking it, make sure to clone the fork by running this:
After cloning the project, run the following to install the dependencies:
Then, run this:
Your application should be running on localhost:8080
. Kill the running server, and let’s install the Vue.js CLI plugin for Tauri.
vue-cli-plugin-tauri
The Tauri team created a Vue.js CLI plugin that quickly rigs and turns your Vue.js single-page application (SPA) into a tiny cross-platform desktop app that is both fast and secure. Let’s install that plugin:
After the plugin is installed, which might take a while, it will ask you for a window title. Just type in nota
and press “Enter”.
Let’s examine the changes introduced by the Tauri plugin.
package.json
The Tauri plugin added two scripts in the scripts section of our package.json
file. They are:
The tauri:serve
script should be used during development. So let’s run it:
The above would download the Rust crates needed to start our app. After that, it will launch our app in development mode, where it will create a WebView window, with debugging and Hot Module Reloading!
src-tauri
You will also notice that the plugin added a src-tauri
directory to the root of your app directory. Inside this directory are files and folders used by Tauri to configure your desktop app. Let’s check out the contents:
The only change we would need to make is in src-tauri/Cargo.toml
. Cargo.toml
is like the package.json
file for Rust. Find the line below in Cargo.toml
:
Change it to this:
That’s all we need to change for this example!
Bundling
To bundle nota
for your current platform, simply run this:
Note: As with the development window, the first time you run this, it will take some time to collect the Rust crates and build everything. On subsequent runs, it will only need to rebuild the Tauri crates themselves.
Apps For Macos Using React Iphone
When the above is completed, you should have a binary of nota
for your current OS. For me, I have a .deb
binary created in the src-tauri/target/release/bundle/deb/
directory.*
Going Cross-Platform
You probably noticed that the yarn tauri:build
command just generated a binary for your operating system. So, let’s generate the binaries for other operating systems. To achieve this, we will set up a workflow on GitHub. We are using GitHub here to serve as a distribution medium for our cross-platform app. So, your users could just download the binaries in the “Release” tab of the project.The workflow we would implement would automatically build our binaries for us via the power of GitHub actions. Let’s get to it.
Creating The Tauri Workflow
Thanks to Jacob Bolda, we have a workflow to automatically create and release cross-platform apps with Tauri on GitHub. Apart from building the binary for the various platforms (Linux, Mac, and Windows), the action would also upload the binary for you as a release on GitHub. It also uses the Create a Release action made by Jacob to achieve this.
To use this workflow, create a .github
directory in the root of nota-web
. In this directory, create another directory named workflows
. We would then create a workflow file in .github/workflows/
, and name it release-tauri-app.yml
.
In release-tauri-app.yml
, we would add a workflow that builds the binaries for Linux, macOS, and Windows. This workflow would also upload the binaries as a draft release on GitHub. The workflow would be triggered whenever we push to the master.
Open release-tauri-app.yml
, and add the snippet below:
To test the workflow, commit and push your changes to your fork’s master
branch. After successfully pushing to GitHub, you can then click on the “Actions” tab in GitHub, then click on the “Check build” link to see the progress of the workflow.
Upon successful execution of the action, you can see the draft release in “Releases” on the repository page on GitHub. You can then go on to publish your release!
Conclusion
This article has introduced a polyglot toolchain for building secure, cross-platform, and tiny native applications. We’ve seen what Tauri is and how to incorporate it with Vue.js. Lastly, we bundled our first Tauri app by running yarn tauri:build
, and we also used a GitHub action to create binaries for Linux, macOS, and Windows.
Let me know what you think of Tauri — I’d be excited to see what you build with it. You can join the Discord server if you have any questions.
The repository for this article is on GitHub. Also, see the binaries generated by the GitHub workflow.