Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@lit-labs/compiler
Advanced tools
Readme
A compiler for optimizing Lit templates.
Warning
@lit-labs/compiler
is part of the Lit Labs set of packages – it is published in order to get feedback on the design and may receive breaking changes. RFC: https://github.com/lit/rfcs/pull/21Give feedback: https://github.com/lit/lit/discussions/4117
@lit-labs/compiler
exports a TypeScript
Transformer
that can be run over your JavaScript or TypeScript files to optimize away the
lit-html
prepare render phase. For template heavy applications this can result in a quicker first render.
This transformer can be used anywhere TypeScript transformers are accepted, which is dependent on your build setup.
Below is an example using Rollup with the plugin @rollup/plugin-typescript
:
// File: rollup.config.js
import typescript from '@rollup/plugin-typescript';
import {compileLitTemplates} from '@lit-labs/compiler';
export default {
// ...
plugins: [
typescript({
transformers: {
before: [compileLitTemplates()],
},
}),
// other rollup plugins
],
};
See an example of the transformer in use in this project's test for source-maps validity in this rollup config file.
Running the compiler requires a build step that can accept a TypeScript transformer.
The very first template render is faster (sometimes up to 45% faster for template heavy pages), but currently the output file is about 5% larger (gzipped).
Given your original source code containing the html
tag function to declare templates:
const hi = (name) => html`<h1>Hello ${name}!</h1>`;
This code should have been emitted at the end of your build without the html
tag function.
E.g. the above authored example is transformed into something like:
const b = (s) => s;
const lit_template_1 = {h: b`<h1>Hello <?></h1>`, parts: [{type: 2, index: 1}]};
const hi = (name) => ({_$litType$: lit_template_1, values: [name]});
In order for a template to be optimized by the compiler, it must be:
html
imported directly from the module lit
or lit-html
. Re-exports of html
from other modules are not supported. The following imports are supported:
import {html} from 'lit';
Usage: html`...`
import {html as litHtml} from 'lit';
Usage: litHtml`...`
import * as litModule from 'lit'
Usage: litModule.html`...`
textarea
, title
, style
, and script
. This is due to these elements containing raw text nodes as children & the limitation that raw text nodes cannot be placed as adjacent children in HTML markup.Because JavaScript is a subset of TypeScript, the TypeScript transform has been implemented and tested such that it handles JavaScript.
You will need to run the compiler transformer over your JavaScript files.
lit-html
runtime that is no longer needed.FAQs
Compiler to prepare Lit templates at build time
The npm package @lit-labs/compiler receives a total of 264 weekly downloads. As such, @lit-labs/compiler popularity was classified as not popular.
We found that @lit-labs/compiler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.