Qwik
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Optimizer Code Transformations ## 1) Developer's Source Code - Find all of the input (TypeScript) source files - Starting at the root dir, walk the child directories to find all typescript files - Cannot use tsconfig.json `files` property because there isn't a single entry - Finding ts files doesn't need to be too accurate - Just find the bare minimum ts compononent files - Overfinding too many ts files is fine - The entry file generation will only pull in what's used - Skips over unit tests, node_modules, build, dist > [name=Miško Hevery] any `qrlHook` function (or any function which is aliased to it `export const qrlBar = qrlHook;`) > > What does the method do? > > - _It replaces all references to the symbol with QRL pointing to the symbol_ **my-counter.tsx** ```typescript import { qComponent, qrlComponenOnInit, qrlComponenOnRender, qrlHandler } from '@builder.io/qwik'; type MyCounter = QComponent<{ step?: number }, { count: number }>; export const onInit = qrlComponentOnInit<MyCounter>(() => ({ count: 0 })); export const onRender = qrlComponentOnRender<MyCounter>(({props, state}) => { return ( <div> <button on:click={increment}>+</button> <span>{state.count}</span> </div> ); }); export const increment = qrlHandler<MyCounter>(({props, state}) => { state.count += props.step || 1; }); export const MyCounter = qComponent<MyCounter>({ onInit, onRender }); ``` **my-app.tsx** ```typescript import { qComponent, qrlView } from '@builder.io/qwik'; import { MyCounter } from './my-counter'; export const onRender = qrlOnRender<MyApp>(() => { return ( <section> <MyCounter /> </section> ); }); export const MyApp = qComponent<MyApp>({ onRender }); ``` ## 2) Static Analysis: Gather module graph and generate entry files - Do a `rollup.build()` to gather all data about each module - Collects import/export data in order to build a module graph - Stores data within the `BuildInfo` which is passed throughout to the build - Uses the same rollup plugins as the client build, to include a user's typescript plugin - Unnecessary to do `rollup.generate()` for this pass - After this first build completes, generate entry files - Uses the module graph from the `BuildInfo` after the first build - Generated code groups certain modules together, re-exports variable names - Can be further optimized to better group modules together - Possible to have variable name collisions, so use "as" and ensure it has a unique export name These are the generated entry files with an algorithm deciding how to best group exports together. It's possible to have variable name collisions with mulitple imported variables using the same name, like `view` or `state`. If there's a collision, ensure they use export `as` and make sure each export has a unique name. > Note: Below isn't the optimial bundling, that's for the algorithm and developer config to do a better job creating. Below is one example. **@qwik-0** ```typescript export { onInit as onInit1 } from './my-counter'; ``` **@qwik-1** ```typescript export { onRender as onRender1 } from './my-counter'; ``` **@qwik-2** ```typescript export { increment as increment1 } from './my-counter'; ``` **@qwik-3** ```typescript export { view as view1 } from './my-app'; ``` ``` src/my-counter#state src/my-counter#view --- src/my-counter#increment src/my-counter#* ``` // # If QRL not found here then end up in [chunk-main] ## 3) Build: Transform and bundle modules The entry file ids are set in Rollup's `input` option. While resolving each import, the unqiue id of each entry file is used to lookup the generated entry code, which was already created after the first-pass source code analysis completed. ```typescript const clientBuild = await rollup({ input: ['@qwik-0', '@qwik-1', '@qwik-2', '@qwik-3'], }); ``` - Use the generated entry files for rollup's `input` build option - Each entry has a unique id which `optimizer.resolve()` will correctly resolve to the generated code - Entry files know export names and source files used to create it - Resolve imports to the entry files instead - If an import can instead be imported from an entry file, resolve to the generated entry - Add the export name as a `#hash` in the import url, needed for the runtime to know the export name - Could become recursive, so if the `importee` is any entry file, then resolve it normally - Rewrite Qwik local variables to standard dynamic `import()` - Let rollup be rollup in order for the bundler to parse/hash/chunk the build urls and output - Trying to accomplish the same thing without the standard `import()` would be reinventing the bundler wheel Below is AFTER the Qwik code transformation happens, but BEFORE javascript output files are generated. - Local variable q functions updated to a dynamic `import()` with an entry file as the url - TypeScript down-leveled to just JavaScript, JSX transformed to `h()` **my-counter.js** ```typescript import { qComponent, qrlHandler, qrlView, qrlState } from '@builder.io/qwik'; export const onInit = qrlComponentOnInit(() => ({ count:0 })); export const onRender = qrlComponentOnRender(({props, state}) => { return ( h("div", null, h("button", { 'on:click': import("@qwik-2#increment1")}, "+"), h("span", null, state.count) ); ); }); export const increment = qrlHandler((props, state) => { state.count += props.step || 1; }); export const MyCounter = qComponent({ onInit: import('@qwik-0#state1'), onRender: import('@qwik-1#view1'), }); ``` **my-app.js** ```typescript import { MyCounter } from './my-counter'; export const onRender = qrlComponentOnRender(() => { return h('section', null, h(MyCounter, null)); }); export const MyApp = qComponent({ onRender: import('@qwik-3#onRender'), }); ``` ## 4) Generate: Output JavaScript Chunks - For the most part the build is done, files are hashed and urls are linking correctly to one another - Rollup has linked the modules together and created the chunk urls to sibling chunks - Last hook is to rewrite `import()` calls to instead just be the url string itself, removing `import(` and `)` - Value for `on:click` handler is just a string to a url now, not an `import()` call **q-abcd.js** ```typescript import { qrlComponentInit } from './q-core.js'; export const stateMyCounter = qrlComponentInit(() => ({ count: 0 })); ``` **q-cdef.js** ```typescript import { qrlComponentOnRender } from './q-core.js'; export const viewMyCounter = qrlComponentOnRender((props, state) => { return ( h("div", null, h("button", { 'on:click': './q-efgh#increment1' }, "+"), h("span", null, state.count) ); ); }); ``` **q-efgh.js** ```typescript import { qrlHandler } from './q-core.js'; export const incrementMyCounter = qrlHandler(({props, state}) => { state.count += props.step || 1; }); ``` **q-ghjk.js** ```typescript import { qComponent, qrlView } from './q-core.js'; export const MyCounter = qComponent({ view: './q-cdef.js#view1', }); export const MyAppOnRender = qrlComponentOnRender(() => { return h('section', null, h(MyCounter, null)); }); ``` **q-klmn.js** ```typescript import { qComponent } from './q-core.js'; export const MyApp = qComponent({ view: './q-ghjk.js#MyAppOnRender1', }); ```

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully