skysan's 雑記帳

思ったことなどを気ままに。主にプログラミングの話を書いてます。

DockerでLWC Dev Serverを起動する(廃止)

2025/4/5追記

LWC Dev Serverは廃止予定のため、参照しないようにしてください。 新しいツールが提供予定とのこと。

Migrate to the new Local Dev experience before we eventually deprecate the LWC Local Development Server. Local Dev lets you quickly iterate on your Lightning web components in a real-time preview of your Lightning app or Experience Cloud Lightning Web Runtime site, without deploying code or manually refreshing the preview.

LWC Local Development Server (Beta) | Salesforce Extensions for Visual Studio Code | Salesforce Developers

はじめに

DockerのSFDX開発環境にLWC ローカル開発サーバをインストールする。

通常sfdxコマンドからプラグインをインストールだけだが、事前に必要なモジュールがいくつかあり調査したので、備忘録として残しておく

前準備

skysan87.hatenablog.com

開発環境

インストール

エラーも一部抜粋して記載

lwc-dev-serverをインストール

$ sfdx plugins:install @salesforce/lwc-dev-server

(中略)

Please make sure you are using a supported platform and node version. If you
would like to compile fibers on this machine please make sure you have setup your
build environment--
Windows + OS X instructions here: https://github.com/nodejs/node-gyp
Ubuntu users please run: `sudo apt-get install g++ build-essential`
RHEL users please run: `yum install gcc-c++` and `yum groupinstall 'Development Tools'` 
Alpine users please run: `sudo apk add python make g++`
/bin/sh: 1: nodejs: not found

モジュールがインストールされていないため、エラーとなる。 Dockerイメージのディストリビューションを調べる。

$ cat /etc/os-release

NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Ubuntuなので、メッセージ通りのコマンドを実行する。

$ apt-get update
$ apt-get install g++ build-essential

再度インストールを実行する。

$ sfdx plugins:install @salesforce/lwc-dev-server

完了。

ローカルサーバの実行

サーバが起動すると、自動でポートも開く。サーバを停止すれば、ポートも閉じる。すげー。

# CLIからの実行
$ sfdx force:lightning:lwc:start

VSCode拡張機能からも起動可能(記載は略)。

まとめ

公式DockerイメージはUbuntuなので、以下のコマンドをする。

$ apt-get update
$ apt-get install g++ build-essential
$ sfdx plugins:install @salesforce/lwc-dev-server

参考