debian-mirror-gitlab/doc/user/project/pages/public_folder.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
3.7 KiB
Markdown
Raw Normal View History

2022-10-11 01:57:18 +05:30
---
description: 'Learn how to configure the build output folder for the most
common static site generators'
stage: Create
2023-03-04 22:38:38 +05:30
group: Editor
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2022-10-11 01:57:18 +05:30
---
# Configure the public files folder **(FREE)**
2023-03-04 22:38:38 +05:30
All the files that should be accessible by the browser must be in a root-level folder called `public`.
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
Follow these instructions to configure the `public` folder
for the following frameworks.
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
## Eleventy
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
For Eleventy, you should do one of the following:
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
- Add the `--output=public` flag in Eleventy's build commands, for example:
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
`npx @11ty/eleventy --input=path/to/sourcefiles --output=public`
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
- Add the following to your `.eleventy.js` file:
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
```javascript
// .eleventy.js
module.exports = function(eleventyConfig) {
return {
dir: {
output: "public"
}
}
};
```
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
## Astro
2022-10-11 01:57:18 +05:30
By default, Astro uses the `public` folder to store static assets. For GitLab Pages,
rename that folder to a collision-free alternative first:
1. In your project directory, run:
```shell
mv public static
```
1. Add the following to your `astro.config.mjs`. This code informs Astro about
our folder name remapping:
```javascript
// astro.config.mjs
2022-11-25 23:54:43 +05:30
import { defineConfig } from 'astro/config';
export default defineConfig({
2022-10-11 01:57:18 +05:30
// GitLab Pages requires exposed files to be located in a folder called "public".
// So we're instructing Astro to put the static build output in a folder of that name.
2022-11-25 23:54:43 +05:30
outDir: 'public',
2022-10-11 01:57:18 +05:30
// The folder name Astro uses for static files (`public`) is already reserved
// for the build output. So in deviation from the defaults we're using a folder
// called `static` instead.
2022-11-25 23:54:43 +05:30
publicDir: 'static',
});
2022-10-11 01:57:18 +05:30
```
2023-03-04 22:38:38 +05:30
## SvelteKit
2022-10-11 01:57:18 +05:30
NOTE:
GitLab Pages supports only static sites. For SvelteKit,
2023-03-04 22:38:38 +05:30
you can use [`adapter-static`](https://kit.svelte.dev/docs/adapters#supported-environments-static-sites).
2022-10-11 01:57:18 +05:30
When using `adapter-static`, add the following to your `svelte.config.js`:
```javascript
// svelte.config.js
import adapter from '@sveltejs/adapter-static';
export default {
kit: {
adapter: adapter({
pages: 'public'
})
}
};
```
2023-03-04 22:38:38 +05:30
## Next.js
2022-10-11 01:57:18 +05:30
NOTE:
2023-03-04 22:38:38 +05:30
GitLab Pages supports only static sites. For Next.js, you can use
Next's [Static HTML export functionality](https://nextjs.org/docs/advanced-features/static-html-export).
2022-10-11 01:57:18 +05:30
Use the `-o public` flag after `next export` as the build command, for
example:
```shell
next export -o public
```
### Nuxt.js
NOTE:
GitLab Pages supports only static sites.
1. Add the following to your `nuxt.config.js`:
```javascript
export default {
target: 'static',
generate: {
dir: 'public'
}
}
```
1. Configure your Nuxt.js application for
2023-01-13 00:05:48 +05:30
[Static Site Generation](https://nuxtjs.org/docs/features/deployment-targets/#static-hosting).
2022-10-11 01:57:18 +05:30
2023-03-04 22:38:38 +05:30
## Vite
2022-10-11 01:57:18 +05:30
Update your `vite.config.js` to include the following:
```javascript
// vite.config.js
export default {
build: {
outDir: 'public'
}
}
```
2023-03-04 22:38:38 +05:30
## Webpack
2022-10-11 01:57:18 +05:30
Update your `webpack.config.js` to include the following:
```javascript
// webpack.config.js
module.exports = {
output: {
path: __dirname + '/public'
}
};
```
## Should you commit the `public` folder?
Not necessarily. However, when the GitLab Pages deploy pipeline runs, it looks
2023-03-04 22:38:38 +05:30
for an [artifact](../../../ci/pipelines/job_artifacts.md) of that name.
2022-10-11 01:57:18 +05:30
If you set up a job that creates the `public` folder before deploy, such as by
running `npm run build`, committing the folder isn't required.
If you prefer to build your site locally, you can commit the `public` folder and
2023-03-04 22:38:38 +05:30
omit the build step during the job instead.