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 install
npm run dev

第一个命令将在 my-app 目录中搭建一个新项目,询问你是否要设置一些基本工具,例如 TypeScript。有关设置其他工具的指针,请参阅 integrations。随后的命令将安装其依赖并在 localhost:5173 上启动服务器。

¥The first command will scaffold a new project in the my-app directory asking you if you’d like to set up some basic tooling such as TypeScript. See integrations for pointers on setting up additional tooling. The subsequent commands will then install its dependencies and start a server on localhost:5173.

有两个基本概念:

¥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.

上一页 下一页