### Starts the server
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/integration-wdio/README.md
Starts the server (not needed for testing).
```shell
yarn start
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/style-compiler/README.md
Install the @lwc/style-compiler package as a dev dependency.
```sh
yarn add --dev @lwc/style-compiler
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/rollup-plugin/README.md
Install the @lwc/rollup-plugin using yarn.
```sh
yarn add --dev @lwc/rollup-plugin
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/template-compiler/README.md
Install the @lwc/template-compiler package as a dev dependency.
```sh
yarn add --dev @lwc/template-compiler
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/babel-plugin-component/README.md
Install the babel core and the LWC component babel plugin.
```bash
npm install babel @lwc/babel-plugin-component
```
--------------------------------
### Install Dependencies
Source: https://github.com/salesforce/lwc/blob/master/CONTRIBUTING.md
Installs project dependencies using Yarn.
```bash
yarn install
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/compiler/README.md
Install the @lwc/compiler package using npm.
```sh
npm install @lwc/compiler
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/aria-reflection/README.md
Install the @lwc/aria-reflection package using npm.
```shell
npm install @lwc/aria-reflection
```
--------------------------------
### Module Resolution Configuration Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/module-resolver/README.md
Example of lwc.config.json file configuring module resolution with alias, directory, and NPM package records.
```json
// lwc.config.json
{
"modules": [
{
"name": "ui/button",
"path": "src/modules/ui/button/button.js"
},
{
"dir": "src/modules"
},
{
"npm": "@ui/components"
}
]
}
```
--------------------------------
### Usage Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/template-compiler/README.md
Example of how to use the compile function from the @lwc/template-compiler package.
```js
import { compile } from '@lwc/template-compiler';
const filename = 'component.html';
const options = {};
const { code, warnings } = compile(
`
Hello World!
`,
filename,
options
);
for (let warning of warnings) {
console.log(warning.message);
}
console.log(code);
```
--------------------------------
### Importing from 'lwc/engine-server'
Source: https://github.com/salesforce/lwc/blob/master/packages/lwc/README.md
Example of importing a module from the convenience 'lwc' package.
```js
import { renderComponent } from 'lwc/engine-server';
```
--------------------------------
### Compile API Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/template-compiler/README.md
Example of using the compile API with minimal options.
```js
import { compile } from '@lwc/template-compiler';
const { code, warnings } = compile(`Hello World!
`, {});
```
--------------------------------
### Manual Testing Setup
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/perf-benchmarks/README.md
Command to set up and run a benchmark for manual testing in Chrome DevTools.
```shell
cd packages/@lwc/perf-benchmarks
yarn tach --manual --config dist/__benchmarks__/path/to/tachometer.json
```
--------------------------------
### Creating a ReactiveObserver instance
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/engine-core/src/libs/mutation-tracker/README.md
This example shows how to create a ReactiveObserver and observe property access.
```javascript
import { ReactiveObserver } from '../libs/mutation-tracker';
const ro = new ReactiveObserver(() => {
// this callback will be called when tracked property `x` of `o`
// is mutated via `valueMutated` in the future.
});
ro.observe(() => {
// every time observe() is invoked, the callback will be immediately
// called, and any observed value will be recorded and linked to this
// ReactiveObserver instance, in case a mutation happens in the future.
valueObserved(o, 'x');
});
```
--------------------------------
### LightningElement base class example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/engine-core/README.md
Provides an example of extending the LightningElement class to create an LWC constructor.
```js
import { LightningElement } from 'lwc';
class LightningHello extends LightningElement {
// component implementation
}
```
--------------------------------
### Installation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/module-resolver/README.md
Install the @lwc/module-resolver package as a dev dependency.
```sh
npm install --save-dev @lwc/module-resolver
```
--------------------------------
### Directory Module Record Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/module-resolver/README.md
Example of a directory module record specifying a folder path for module resolution.
```json
{
"modules": [
{
"dir": "src/modules"
}
]
}
```
--------------------------------
### Alias Module Record Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/module-resolver/README.md
Example of an alias module record mapping a module specifier to a file path.
```json
{
"modules": [
{
"name": "ui/button",
"path": "src/modules/ui/button/button.js"
}
]
}
```
--------------------------------
### Example Commit Message (Docs)
Source: https://github.com/salesforce/lwc/blob/master/CONTRIBUTING.md
An example of a commit message for documentation changes.
```git
docs(changelog): update change log to beta.5
```
--------------------------------
### getBook wire adapter implementation
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/wire-service/README.md
An example implementation of a wire adapter named getBook, demonstrating connect, disconnect, and update methods.
```javascript
// wire-adapter.js
import { bookEndpoint } from './server';
export class getBook {
connected = false;
bookId;
constructor(dataCallback) {
this.dataCallback = dataCallback;
}
connect() {
this.connected = true;
this.provideBookWithId(this.bookId);
}
disconnect() {
this.connected = false;
}
update(config) {
if (this.bookId !== config.id) {
this.bookId = config.id;
this.provideBookWithId(this.bookId);
}
}
provideBookWithId(id) {
if (this.connected && this.bookId !== undefined) {
const book = bookEndpoint.getById(id);
if (book) {
this.dataCallback(Object.assign({}, book));
} else {
this.dataCallback(null);
}
}
}
}
```
--------------------------------
### Usage
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/style-compiler/README.md
Example of using the transform function from the @lwc/style-compiler package.
```js
import { transform } from '@lwc/style-compiler';
const source = `
:host {
opacity: 0.4;
}
span {
text-transform: uppercase;
}
`;
const { code } = transform(source, 'example.css');
```
--------------------------------
### Usage
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/rollup-plugin/README.md
Example rollup.config.js configuration using the @lwc/rollup-plugin.
```js
// rollup.config.js
import lwc from '@lwc/rollup-plugin';
export default {
input: './src/main.js',
plugins: [lwc()],
};
```
--------------------------------
### @wire decorator example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/engine-core/README.md
Shows how to use the @wire decorator to wire fields and methods to a wire adapter.
```js
import { LightningElement, wire } from 'lwc';
import { getRecord } from 'recordDataService';
export default class Test extends LightningElement {
@wire(getRecord, { id: 1 })
recordData;
}
```
--------------------------------
### Usage
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/babel-plugin-component/README.md
Example of using the @lwc/babel-plugin-component with @babel/core.
```javascript
import babel from '@babel/core';
import lwcPlugin from '@lwc/babel-plugin-component';
const source = `
import { LightningElement } from 'lwc';
export default class extends LightningElement {}`;
const { code } = babel.transformSync(source, {
plugins: [
[
lwcPlugin,
{
/* options */
},
],
],
});
```
--------------------------------
### Directory structure for contributing tests
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/integration-wdio/README.md
Example directory structure for contributing tests, emphasizing one repro per test case.
```shell
lwc-integration/src/components/
--
----
------.html
------.js
----app
------app.html
------app.js
----child
------child.html
------child.js
----.spec.js
```
```shell
lwc-integration/src/components/
--
----.html
----.js
----.spec.js
```
--------------------------------
### Pull Request Title Format Example
Source: https://github.com/salesforce/lwc/blob/master/CONTRIBUTING.md
Example of the conventional commit format for pull request titles.
```shell
ex:
commit-type(optional scope): commit description. ( NOTE: space between column and the message )
Types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test, proposal.
Scope: The scope should be the name of the npm package affected (engine, compiler, wire-service, etc.)
```
--------------------------------
### Dev / watch mode
Source: https://github.com/salesforce/lwc/blob/master/CONTRIBUTING.md
Starts the development server in watch mode for continuous building.
```bash
yarn dev
```
--------------------------------
### Force Clean NPM Install
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/perf-benchmarks/README.md
Flag to use when comparing to another branch if issues arise, ensuring a clean npm install.
```shell
--force-clean-npm-install
```
--------------------------------
### Example Commit Message (Fix)
Source: https://github.com/salesforce/lwc/blob/master/CONTRIBUTING.md
An example of a commit message for a bug fix, including a body explaining the motivation.
```git
fix(release): need to depend on latest rxjs and zone.js
The version in our package.json gets copied to the one we publish, and users need the latest of these.
```
--------------------------------
### Scoped Styles Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/ssr-compiler/src/__tests__/fixtures/light-dom-scoped-styles/expected.html
Example of CSS rules applied with scoped styles in Light DOM.
```css
p {color: red;} p.lwc-1rssj1tib70 {background-color: blue;}.lwc-1rssj1tib70-host {display: block;border: 1px solid black;}
```
--------------------------------
### ARIA Reflection Example
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/aria-reflection/README.md
Demonstrates how aria attributes are reflected to properties and vice versa.
```javascript
element.setAttribute('aria-pressed', 'true');
console.log(element.ariaPressed); // true
element.ariaPressed = false;
console.log(element.getAttribute('aria-pressed')); // false
```
--------------------------------
### Filter Benchmarks with GREP
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/perf-benchmarks/README.md
Example of using the GREP environment variable to filter benchmarks by filename using regular expressions.
```shell
GREP='ssr' yarn test
```
--------------------------------
### Custom Renderer Config Example 1
Source: https://github.com/salesforce/lwc/blob/master/packages/@lwc/template-compiler/README.md
Configuration to match '