gridsome的安装使用

785 阅读1分钟

一、安装 Gridsome CLI

// 使用 npm
npm install --global @gridsome/cli

// 使用 yarn
yarn global add @gridsome/cli

// 查看是否安装成功
gridsome -v

二、创建 Gridsome 项目

  • 由于国内网络的原因直接使用 gridsome create my-gridsome-site 创建会导致安装报错,所以必须先执行下列步骤
  • 安装 Gridsome 注意事项:
    • 安装配置 node-gyp 编译环境

      On Windows
      Install the current version of Python from the Microsoft Store package.
      Option 1
      Install all the required tools and configurations using Microsoft's windows-build-tools using npm install --global windows-build-tools from an elevated PowerShell or CMD.exe (run as Administrator).

      • 意思在 window 下安装(本人使用的是 window)node-gyp 必须先有 python 环境,然后提供一个包来直接完成这个步骤。npm install --global windows-build-tools 使用管理者身份安装此包,出现 All done! 则说明安装成功
      • 此时可以安装 node-gyp 了,运行安装:npm install -g node-gyp
    • 配置安装 sharp 的环境变量
      • 修改镜像配置文档地址 sharp.pixelplumbing.com/install#chi…
      • npm config set sharp_binary_host "https://npm.taobao.org/mirrors/sharp"
      • npm config set sharp_libvips_binary_host "https://npm.taobao.org/mirrors/sharp-libvips"
    • 因为 raw.githubusercontent.com 访问受限,需要修改 hosts 文件
      • 199.232.68.133 raw.githubusercontent.com
  • 执行完上述步骤就可以执行安装命令了
// 创建 gridsome 项目文件夹
gridsome create my-gridsome-site

// 进入文件夹
cd my-gridsome-site

// 启动服务
npm run develop

看到下面界面就可以恭喜你,启动成功了