Skip to content

Commit 0e32a7f

Browse files
authored
Merge pull request #329 from valor-software/article-qwik-reaches
feat(article): added qwik-reaches-v1 article
2 parents 0804e17 + 86913e4 commit 0e32a7f

7 files changed

Lines changed: 223 additions & 1 deletion

File tree

328 KB
Loading
486 KB
Loading
62.5 KB
Loading
13.3 KB
Loading
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
== Introduction
2+
A lot has happened since we https://dev.to/valorsoftware/introducing-qwik-integration-for-nx-1k5b[introduced, window=_blank] the https://github.com/qwikifiers/qwik-nx[qwik-nx, window=_blank], an official plugin for the Qwik framework. As Qwik breaks free by reaching the v1, we’re happy to announce the release of the stable version of the Nx integration for it.
3+
4+
=== A few words about Qwik
5+
Qwik is referred to as a next-generation framework because of its revolutionary new approaches to performance optimization, among which:
6+
7+
* *JavaScript Streaming* - an ability to load and execute only the bare minimum of the code as Qwik analyses and splits your code into chunks up to a function level. Those chunks are prefetched in a separate thread, similar to "buffering" in video streaming. The prefetched code only executes upon user action;
8+
9+
* *resumability* - a new rendering paradigm to bring you instantly interactive apps by serializing/deserializing your app as it goes from SSR to client without the need for hydration;
10+
11+
In practise this means that you get an app with O(1) size, as its initial bundle is constant at about 1kb no matter the application complexity.
12+
13+
[.img]
14+
image::img1.png[]
15+
16+
This is extremely beneficial for enterprise companies, that usually want to bring an enormous amount of functionality to their users without any performance impact.
17+
18+
While Qwik helps to scale the application's functionality expressed via code without effort, Nx is there to make sure your codebase can be managed at any scale. And here's where qwik-nx comes into play. It provides the same experience of the generation and execution of Qwik applications in an Nx workspace that fits the standards of other Nx projects.
19+
20+
=== What's new?
21+
In the https://dev.to/valorsoftware/introducing-qwik-integration-for-nx-1k5b[previous article, window=_blank], we have talked about how you get started by initializing your Nx repository with Qwik.
22+
23+
Recap: you can generate a new workspace by running:
24+
[, bash]
25+
----
26+
npx create-nx-workspace@latest org-workspace --preset=qwik-nx
27+
----
28+
29+
Or add a new Qwik application to an existing workspace by running:
30+
[, bash]
31+
----
32+
npm install -D qwik-nx
33+
----
34+
35+
and then
36+
[, bash]
37+
----
38+
nx generate qwik-nx:app
39+
----
40+
Today let's talk about what new opportunities does it offer:
41+
42+
=== #qwikNxVite# plugin
43+
44+
If you stick to using Qwik with Nx from its first days, you might have noticed that importing Qwik components from libraries does not work out of the box as all those dependencies should be configured as #vendorRoots# for #qwikVite# plugin in order for Qwik Optimizer to actually include and process them.
45+
46+
The good news is you don't have to do it manually any more: #qwikNxVite# plugin will by default analyze the Nx dependency graph and put all libraries your app uses as vendorRoots for the Qwik Optimizer to consume.
47+
48+
[, ts]
49+
----
50+
// vite.config.ts
51+
52+
import { qwikNxVite } from 'qwik-nx/plugins';
53+
54+
export default defineConfig({
55+
plugins: [
56+
qwikNxVite(), // <= that's all you need!
57+
qwikCity(),
58+
qwikVite(),
59+
tsconfigPaths({ root: '../../' }),
60+
],
61+
...
62+
});
63+
----
64+
65+
And this behavior can be fine-tuned even further to make sure you're including only what's intended. As an example, you can mark all Qwik-specific libraries with a specific tag and filter your vendorRoots with it. Let's see how you can leverage the usage of #"framework:qwik"# tag.
66+
67+
1) Mark libs you need with the respective tag:
68+
69+
[, ts]
70+
----
71+
// some lib's project.json
72+
{
73+
...
74+
"tags": ["type:ui", "scope:products", "framework:qwik"]
75+
}
76+
----
77+
78+
2) Configure the plugin
79+
80+
[, ts]
81+
----
82+
// app's vite.config.ts
83+
qwikNxVite({
84+
// filter out all projects that does not have this tag
85+
// use "tags", "name", "path" regex
86+
// or even "customFilter" to achieve desired filtering logic
87+
includeProjects: { tags: ["framework:qwik"] }
88+
debug: true // <= put this to see what projects are included
89+
})
90+
----
91+
92+
This configuration will make #qwikNxVite# plugin to load only libraries that have respective tag AND are recognized by Nx as your app's dependency.
93+
94+
=== Pro tip
95+
You can configure the Nx Console to always put the tag you want as a default value for the #tags# field for the #qwik-nx:library# generator. This can be achieved by setting that default value in the https://nx.dev/reference/nx-json[build options of nx.json, window=_blank]
96+
97+
[, ts]
98+
----
99+
{
100+
"generators": {
101+
"qwik-nx:library": {
102+
"tags": "framework:qwik"
103+
}
104+
}
105+
}
106+
----
107+
108+
[.img]
109+
image:img2.png[]
110+
111+
=== Automatic versions migrations
112+
113+
One of the biggest benefits of using Nx to manage the codebase is their seamless migration process: with a single command #nx migrate latest# Nx CLI will analyze the workspace and provide the set of migrations written by Nx team to update versions of your dependencies and mutate all necessary bits of code. This is a great capability that allows large codebases to always stay up to date without investing weeks of refactoring.
114+
115+
#qwik-nx# aims to provide the same feature for its users to make sure your Qwik apps are updated. This means you don't have to update the app's dependencies manually anymore, just run
116+
#nx migrate qwik-nx@latest# and you are done: it will update all breaking changes and bump versions of Qwik packages.
117+
118+
=== React integration
119+
Qwik https://qwik.builder.io/docs/integrations/react/[offers a great capability, window=_blank] to #qwikify$# React components - reuse existing React components and libraries within Qwik applications. Not only does this open the world of using existing UI libraries (Material UI, Threejs, React Spring, etc.) and utilities that were developed for React over time within Qwik applications, but also this turns out to be a powerful *migration strategy*, as you can migrate your existing React applications chunk by chunk, preserving large parts of functionality in the old syntax without a need to rewrite everything at once.
120+
121+
As React and Qwik components can not be mixed in the same file, if you check your project right after adding React integration to a plain Qwik app, you will see a new folder #src/integrations/react/#, and its recommended to place all React components there.
122+
123+
#qwik-nx# gives you more control over structuring your "qwikified" react code by defining 2 approaches for you:
124+
125+
* use a #react-in-app# generator, that behaves in the same manner as native Qwik integration. It will add integrations/react folder in the existing Qwik app
126+
127+
* #react-library# generator, which will create a separate library to keep qwikified components in it. This means you can now structure your React code as you need and still be able to use it within Qwik apps.
128+
129+
In the Qwik repository there're opened PRs for Angular, Vue and Svelte integrations. As soon as they're available, you will also be able to generate separate libraries for components of those frameworks.
130+
131+
=== Storybook integration
132+
#qwik-nx# now supports adding storybooks for your apps and libs! We get you covered in all scenarios:
133+
134+
* run #nx g qwik-nx:storybook-configuration# to add storybook to your existing libs and apps
135+
* generate a new library with a preconfigured storybook and stories for newly generated components by running #nx g qwik-nx:library mylib --storybookConfiguration#
136+
* add a new component along with a story for it by running #nx g qwik-nx:component --generateStories#
137+
138+
=== Deployments
139+
Qwik offers a variety of ways to deploy your app with its CLI, such as Netlify, Cloudflare Pages, Azure, Vercel, etc. With qwik-nx, we already provide support for Cloudflare Pages with Netlify and other integrations on their way.
140+
141+
To try it out, all you have to do is run #nx g qwik-nx:cloudflare-pages-integration myapp#. This will create a Cloudflare adapter and add necessary targets to preview and deploy your website with Wrangler (Cloudflare CLI tool).
142+
143+
=== Build executor
144+
As you probably know, Qwik builds your code twice, running a client build first and an SSR one after that. In the Nx world, each step of the process is supposed to be a separate target of the application, so that you can keep full control of what you're building.
145+
146+
To achieve this, we're exposing real build steps and wrapping them into our custom build executor.
147+
148+
[, json]
149+
----
150+
{
151+
"targets": [
152+
"build": {
153+
"executor": "qwik-nx:build",
154+
"options": {
155+
"runSequence": [
156+
"myapp:build.client",
157+
"myapp:build.ssr"
158+
],
159+
"outputPath": "dist/apps/myapp"
160+
}
161+
},
162+
"build.client": {
163+
"executor": "@nrwl/vite:build",
164+
"options": {
165+
"outputPath": "dist/apps/myapp",
166+
"configFile": "apps/myapp/vite.config.ts"
167+
}
168+
},
169+
"build.ssr": {
170+
"executor": "@nrwl/vite:build",
171+
"options": {
172+
"outputPath": "dist/apps/myapp"
173+
}
174+
}
175+
]
176+
}
177+
----
178+
179+
The cool thing with this build executor is that you can customize and add additional targets to the build process if that's needed. For example, you can add "myapp:i18n" target to the #runSequence# property in order to process your translations after building the app.
180+
181+
Oh, and keep in mind that #build# executor has another important purpose: it runs type checks for your app before building it!
182+
183+
=== Micro frontends
184+
Qwik is able to render https://qwik.builder.io/docs/advanced/containers/[multiple application instances, window=_blank] within the page as it can be attached to an HTML element, that becomes the root of the application. Inspired by this https://blog.cloudflare.com/better-micro-frontends/[awesome article, window=_blank], we've added micro-frontend support to the Qwik apps. As of now this functionality is in beta
185+
186+
The intent is to bring the same level of convenience as what you get with Nx's tooling to generate and run https://nx.dev/recipes/module-federation/module-federation-with-ssr[Module Federation setup, window=_blank] with React and Angular.
187+
188+
#qwik-nx# provides all necessary generators and executors to use it with ease.
189+
190+
To get started, run the following:
191+
192+
* #nx g qwik-nx:host shell --remotes=products,settings#, which will scaffold the host application and 2 remotes for it
193+
* #nx g qwik-nx:remote myanotherremote --host=shell# to add a new remote application to your existing setup
194+
195+
That is it! You can now run either #nx serve shell# or #nx preview shell# and see both host and remotes built and served together. This is because #qwik-nx#'s executors for serve and preview are able to process all remotes for you with 0 configuration.
196+
197+
=== Excited? Go try it out!
198+
The package already provides a solid way of working with Qwik applications within Nx workspaces. Our main goal is to eventually reach feature parity with Qwik CLI.
199+
200+
So feel free to try it out and let us know how it works out for you!
201+
202+
You are welcome to join the https://discord.com/invite/ndsMfSdR[Qwikifiers, window=_blank] and https://discord.com/invite/nM8hQ7yr[Qwik, window=_blank] Discord servers to keep track of any updates or find any help you need.
203+
204+
We are also looking forward to see any https://github.com/qwikifiers/qwik-nx[new contributions, window=_blank] to the package itself.
205+
206+
Last but not least, we'd like to extend a heartfelt thank you to https://twitter.com/ryanhutchison[Ryan Hutchison, window=_blank] and https://www.asicentral.com/[ASI Central, window=_blank] for their unwavering support of our project and making.
207+
208+
=== Need Help?
209+
At Valor Software, we are passionate about staying at the forefront of technology and are integration partners with the creators of Qwik, Builder.io. If you have any questions or need assistance with your project, don't hesitate to contact us at mailto:sales@valor-software.com[sales@valor-software.com]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"title": "Qwik reaches the v1, so does qwik-nx!",
3+
"order": 73,
4+
"domains": ["dev_quality_assurance"],
5+
"language": "en",
6+
"bgImg": "assets/articles/qwik-reaches-the-v1-so-does-qwik-nx/Main_qwik_reaches.png",
7+
"authorImg": "assets/articles/qwik-reaches-the-v1-so-does-qwik-nx/Dmitry_Stepanenko.png" ,
8+
"author": "Dmitriy Stepanenko",
9+
"position": "Full Stack developer",
10+
"date": "Thu May 04 2023 10:45:55 GMT+0000 (Coordinated Universal Time)",
11+
"seoDescription": "A few words about Qwik"
12+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "nx run-many --all --target=lint",
1212
"runAnotherHost": "nx serve --host=127.0.0.1",
1313
"scully": "npx scully --prod --scanRoutes --project=valor-software-site",
14-
"scully:serve": "npx scully serve --project=valor-software-site"
14+
"scully:serve": "npx scully serve --project=valor-software-site",
15+
"clear-cache": "nx clear-cache"
1516
},
1617
"private": true,
1718
"dependencies": {

0 commit comments

Comments
 (0)