Skip to main content

创建项目

开始构建 SvelteKit 应用的最简单方法是运行 npx sv create

¥The easiest way to start building a SvelteKit app is to run npx sv create:

npx sv create my-app
cd my-app
npm run dev

第一个命令将在 my-app 目录中搭建一个新项目,询问你是否要设置一些基本工具,例如 TypeScript。有关这些选项的信息,请参阅 CLI 文档;有关设置其他工具的指南,请参阅 集成页面npm run dev 随后将在 localhost:5173 上启动开发服务器。 - 如果你在项目创建期间没有安装依赖,请确保在运行此命令之前安装依赖。

¥The first command will scaffold a new project in the my-app directory asking if you’d like to set up some basic tooling such as TypeScript. See the CLI docs for information about these options and the integrations page for pointers on setting up additional tooling. npm run dev will then start the development server on localhost:5173 - make sure you install dependencies before running this if you didn’t do so during project creation.

有两个基本概念:

¥There are two basic concepts:

  • 应用的每个页面都是一个 Svelte 组件

    ¥Each page of your app is a Svelte component

  • 你可以通过将文件添加到项目的 src/routes 目录来创建页面。这些将由服务器渲染,以便用户首次访问你的应用时尽可能快,然后客户端应用接管

    ¥You create pages by adding files to the src/routes directory of your project. These will be server-rendered so that a user’s first visit to your app is as fast as possible, then a client-side app takes over

尝试编辑文件以了解一切的工作原理。

¥Try editing the files to get a feel for how everything works.

编辑器设置(Editor setup)

¥Editor setup

我们建议将 Visual Studio Code(又名 VS Code)Svelte 扩展 一起使用,但 还支持许多其他编辑器 除外。

¥We recommend using Visual Studio Code (aka VS Code) with the Svelte extension, but support also exists for numerous other editors.

上一页 下一页