安装模板 CLI

⚠️

BigCommerce 目前的目标是 2023 年 11 月 1 日停止其 node-sass 分支,转而采用最新的 sass/node-sass (在新选项卡中打开) 为了确保您的店面是最新的,请在 Stencil CLI 中使用最新的节点版本 (Node 18),并使用 CLI 命令解决 不兼容的 SCSS 指令 ,这可能会导致店面样式出现问题。

Stencil CLI 允许开发人员在本地编辑和预览主题,而不影响商家的实时店面及其内置的 Browsersync (在新选项卡中打开) 功能使跨桌面、移动和平板设备的同步测试变得轻而易举。 工作完成后,开发人员可以将主题推送到 BigCommerce 店面,并使用 Stencil CLI 简单但功能强大的命令使它们生效。

本文包含有关安装和配置 Stencil CLI 的详细说明,这是为 BigCommerce 店面开发 Stencil 主题的第一步。

在 Mac 上安装

要在 Mac 上安装 Stencil CLI 及其依赖项,请打开终端并运行以下命令。 请参阅 Stencil CLI README.MD (在新选项卡中打开) 获取支持的最新 node 版本。

这些说明已在 Mac OS X Yosemite 上进行了测试。

# For ARM based macs
arch -x86_64 /bin/zsh
 
# Install Node Version Manager (nvm)
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
 
# Install Stencil CLI supported version of Node.js
nvm install 18.15.0
 
# Switch to Stencil CLI supported version of Node.js:
nvm use 18.15.0
 
# Install Stencil CLI
npm install -g @bigcommerce/stencil-cli

在 Windows 上安装

在 Windows 上安装 Stencil CLI 及其依赖项有两种方法。

方法一:使用Chocolatey安装依赖

如果您喜欢简化的安装选项,请使用 Chocolatey 包管理器 (在新选项卡中打开) 安装 Stencil CLI 的依赖项。 为此, 请打开 PowerShell (在新选项卡中打开) 作为管理员,并运行以下命令:

# Install Chocolatey
iex ((New-Object System.Net.WebClient).DownloadString("https://chocolatey.org/install.ps1"))
 
# Install git if you don't have it
choco install git
 
# Install nvm windows and stencil-compatible node.js
 
choco install nvm; nvm install 18.15.0; nvm use 18.15.0
 
# Install Stencil CLI
npm install -g @bigcommerce/stencil-cli
⚠️

执行策略错误

If you receive an execution policy error while attempting to install chocolatey, refer to Microsoft's Documentation (opens in a new tab) and/or consult with your organization's system administrator to determine the appropriate course of action.

⚠️

Chocolatey installation alternatives

For additional information on installing Chocolatey and alternative installation options, see the installation page on chocolatey.org (opens in a new tab).

Method 2: Install dependencies manually

If you're a pro at installing and configuring Python and Node.js environments on Windows, feel free to install the required dependencies using your preferred method.

Required Dependencies:

Once they're installed and configured, use npm to install Stencil CLI:

npm install -g @bigcommerce/stencil-cli

These instructions have been tested successfully on Windows 10. Refer to Stencil CLI README.MD (opens in a new tab) for latest node version supported.

Installing on Linux

To install Stencil CLI and dependencies on debian-based distros, open a terminal and run the following commands:

# Download and install nvm if you don't have it.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
 
# Reload .bashrc so nvm command works
source ~/.bashrc
 
# Explicitly install and use supported node version
nvm install 18.15.0
 
nvm use 18.15.0
 
# Install stencil
npm install -g @bigcommerce/stencil-cli

Depending on the distro, you may also need to install:

Live previewing a theme

Once you've installed Stencil CLI, the next step on the road to theme development is downloading a theme to edit and previewing live changes using Stencil CLI's powerful Browsersync functionality. For detailed instructions on doing so, see Live Previewing a Theme. Here's the gist:

# move into theme dir
cd ~/path/to/theme/dir
 
# install theme modules
npm install
 
# initialize a new .stencil config for the theme
stencil init
 
# serve a live, Browsersync enabled preview of the theme
stencil start

Troubleshooting

Chocolatey install error

If you receive an error installing Chocolatey, run the following command to enable scripts on your system.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Visual Studio not found error

Stencil CLI's dependencies no longer require Visual C++ build tools to compile.

If you receive the error "Could not find VS", update to the most current version of Stencil CLI and run it using the version of Node.js indicated in this article.

Python npm configuration error

Stencil CLI's dependencies no longer require Python to compile.

如果您收到“错误:找不到任何要使用的 Python 安装”,请更新到最新版本的 Stencil CLI 并使用本文中指示的 Node.js 版本运行它。

资源