To set up Open Web Components, or open-wc, on your Windows 10 machine, we will complete the following steps:
- Install the latest version of Node LTS and NPM
- Install Yarn
- Set up open-wc
Note: To perform the following steps, please be sure to have administrative privileges on your machine and access to the internet.
Node.js and its package manager, known as Node Package Manager (npm) can be installed from this link. Be sure to choose the LTS version when selecting which build of Node to download, and follow the installation prompts that appear upon successful download of the Node installer.
During the installation process, you may be asked to grant certain permissions or accept agreements. You must do so to properly utilize Node.
NPM will automatically install with Node, and you can verify that both of these programs are up-to-date by opening Windows PowerShell and typing the following:
- To determine Node's version:
- To determine npm's version:
Yarn, an alternative version of the aforementioned npm, can be installed from the command line using the following steps:
- Open Windows PowerShell.
npm install -g yarnand press Enter.
If you receive a permissions-related error upon entering this command, your account may not have administrative permissions. To circumvent this, attach
sudoto the beginning of your command. In this case, the command would be
sudo npm install -g yarn.
- Optional: To verify the latest version of yarn has been installed, you can enter the command
Now that we have our dependencies installed, we can set up open-wc!
Before taking these steps, be sure to navigate to the directory in which you would like to do so.
In PowerShell, this can be done using the
cdcommand, followed by your desired directory path.
Once you are in the folder that will contain your web component, you can utilize the following commands in PowerShell to create your component:
npm init @open-wc
- Select "Scaffold a new project" from the options that appear.
- Choose "Web Component" from the new list of options.
- A list of three tooling options (Linting, Testing, and Demoing) will appear. Enable all three.
- Select "no" when asked if you are using Typescript.
- Give your project a name (using lowercase only).
- Select "Yes" to the following prompts: "Write this file structure to a disk" and "Using yarn."
Upon the completion of these steps, your web component is complete!
You can verify this by using
cdfollowed by your project's name to view the directory entry of your project.