Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[breaking] standardize final output dir as /build (vs /.svelte-kit) #2109

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/funny-trainers-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-static': patch
'create-svelte': patch
---

[breaking] standardize final output dir as /build (vs /.svelte-kit)
2 changes: 1 addition & 1 deletion documentation/docs/10-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
};
```

With this, [svelte-kit build](#command-line-interface-svelte-kit-build) will generate a self-contained Node app inside `.svelte-kit/node/build`. You can pass options to adapters, such as customising the output directory in `adapter-node`:
With this, [svelte-kit build](#command-line-interface-svelte-kit-build) will generate a self-contained Node app inside `build`. You can pass options to adapters, such as customising the output directory in `adapter-node`:

```diff
// svelte.config.js
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/80-adapter-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ Within the `adapt` method, there are a number of things that an adapter should d
- Call `utils.prerender`
- Put the user's static files and the generated JS/CSS in the correct location for the target platform

If possible, we recommend putting the adapter output under `'.svelte-kit/' + adapterName` with any intermediate output under `'.svelte-kit/' + adapterName + '/intermediate'`.
If possible, we recommend putting the adapter output under the `build/` directory with any intermediate output placed under `'.svelte-kit/' + adapterName`.

> The adapter API may change before 1.0.
6 changes: 2 additions & 4 deletions packages/adapter-netlify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-bui
```toml
[build]
command = "npm run build"
publish = ".svelte-kit/netlify/build/"
functions = ".svelte-kit/netlify/functions/"
publish = "build/publish/"
functions = "build/functions/"
```

In this example, we placed the `build` and `functions` folders under `.svelte-kit/netlify`. If you specify another location, you will probably also want to add them to your `.gitignore`.

## Netlify alternatives to SvelteKit functionality

You may build your app using functionality provided directly by SvelteKit without relying on any Netlify functionality. Using the SvelteKit versions of these features will allow them to be used in dev mode, tested with integration tests, and to work with other adapters should you ever decide to switch away from Netlify. However, in some scenarios you may find it beneficial to use the Netlify versions of these features. One example would be if you're migrating an app that's already hosted on Netlify to SvelteKit.
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/files/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO hardcoding the relative location makes this brittle
import { init, render } from '../../output/server/app.js'; // eslint-disable-line import/no-unresolved
import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved
import { isContentTypeTextual } from '@sveltejs/kit/adapter-utils'; // eslint-disable-line import/no-unresolved

init();
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export default function (options) {
const files = fileURLToPath(new URL('./files', import.meta.url));

utils.log.minor('Generating serverless function...');
utils.copy(join(files, 'entry.js'), '.svelte-kit/netlify/intermediate/entry.js');
utils.copy(join(files, 'entry.js'), '.svelte-kit/netlify/entry.js');

/** @type {BuildOptions} */
const defaultOptions = {
entryPoints: ['.svelte-kit/netlify/intermediate/entry.js'],
entryPoints: ['.svelte-kit/netlify/entry.js'],
outfile: join(functions, 'render/index.js'),
bundle: true,
inject: [join(files, 'shims.js')],
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
kit: {
adapter: adapter({
// default options are shown
out: '.svelte-kit/node/build',
out: 'build',
precompress: false,
env: {
host: 'HOST',
Expand All @@ -29,7 +29,7 @@ export default {

### out

The directory to build the server to. It defaults to `.svelte-kit/node/build` — i.e. `node .svelte-kit/node/build` would start the server locally after it has been created.
The directory to build the server to. It defaults to `build` — i.e. `node build` would start the server locally after it has been created.

### precompress

Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const pipe = promisify(pipeline);
* }} options
*/
export default function ({
out = '.svelte-kit/node/build',
out = 'build',
precompress,
env: { host: host_env = 'HOST', port: port_env = 'PORT' } = {},
esbuild: esbuildConfig
Expand All @@ -54,16 +54,16 @@ export default function ({

utils.log.minor('Building server');
const files = fileURLToPath(new URL('./files', import.meta.url));
utils.copy(files, '.svelte-kit/node/intermediate');
utils.copy(files, '.svelte-kit/node');
writeFileSync(
'.svelte-kit/node/intermediate/env.js',
'.svelte-kit/node/env.js',
`export const host = process.env[${JSON.stringify(
host_env
)}] || '0.0.0.0';\nexport const port = process.env[${JSON.stringify(port_env)}] || 3000;`
);
/** @type {BuildOptions} */
const defaultOptions = {
entryPoints: ['.svelte-kit/node/intermediate/index.js'],
entryPoints: ['.svelte-kit/node/index.js'],
outfile: join(out, 'index.js'),
bundle: true,
external: Object.keys(JSON.parse(readFileSync('package.json', 'utf8')).dependencies || {}),
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default [
sourcemap: true
},
plugins: [nodeResolve(), commonjs(), json()],
external: ['../../output/server/app.js', './env.js', ...require('module').builtinModules]
external: ['../output/server/app.js', './env.js', ...require('module').builtinModules]
},
{
input: 'src/shims.js',
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO hardcoding the relative location makes this brittle
import { init, render } from '../../output/server/app.js'; // eslint-disable-line import/no-unresolved
import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved
import { host, port } from './env.js'; // eslint-disable-line import/no-unresolved
import { createServer } from './server';

Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-static/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default {
kit: {
adapter: adapter({
// default options are shown
pages: '.svelte-kit/static/build',
assets: '.svelte-kit/static/build',
pages: 'build',
assets: 'build',
fallback: null
})
}
Expand All @@ -28,7 +28,7 @@ Unless you're in [SPA mode](#spa-mode), the adapter will attempt to prerender ev

### pages

The directory to write prerendered pages to. It defaults to `.svelte-kit/static/build`.
The directory to write prerendered pages to. It defaults to `build`.

### assets

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* fallback?: string;
* }} [opts]
*/
export default function ({ pages = '.svelte-kit/static/build', assets = pages, fallback } = {}) {
export default function ({ pages = 'build', assets = pages, fallback } = {}) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-static',
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-static/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from './utils.js';

run('prerendered', (test) => {
test('generates HTML files', ({ cwd }) => {
assert.ok(fs.existsSync(`${cwd}/.svelte-kit/static/build/index.html`));
assert.ok(fs.existsSync(`${cwd}/build/index.html`));
});

test('prerenders content', async ({ base, page }) => {
Expand All @@ -15,15 +15,15 @@ run('prerendered', (test) => {

run('spa', (test) => {
test('generates a fallback page', ({ cwd }) => {
assert.ok(fs.existsSync(`${cwd}/.svelte-kit/static/build/200.html`));
assert.ok(fs.existsSync(`${cwd}/build/200.html`));
});

test('does not prerender pages without prerender=true', ({ cwd }) => {
assert.ok(!fs.existsSync(`${cwd}/.svelte-kit/static/build/index.html`));
assert.ok(!fs.existsSync(`${cwd}/build/index.html`));
});

test('prerenders page with prerender=true', ({ cwd }) => {
assert.ok(fs.existsSync(`${cwd}/.svelte-kit/static/build/about/index.html`));
assert.ok(fs.existsSync(`${cwd}/build/about/index.html`));
});

test('renders content in fallback page when JS runs', async ({ base, page }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-static/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function run(app, callback) {
const cwd = fileURLToPath(new URL(`apps/${app}`, import.meta.url));
const cli_path = fileURLToPath(new URL('../../kit/src/cli.js', import.meta.url));

rimraf(`${cwd}/.svelte-kit/static/build`);
rimraf(`${cwd}/build`);

await spawn(`"${process.execPath}" ${cli_path} build`, {
cwd,
Expand All @@ -41,7 +41,7 @@ export function run(app, callback) {

context.cwd = cwd;
context.port = await ports.find(4000);
const handler = sirv(`${cwd}/.svelte-kit/static/build`, {
const handler = sirv(`${cwd}/build`, {
single: '200.html'
});
context.server = await create_server(context.port, handler);
Expand Down
1 change: 1 addition & 0 deletions packages/create-svelte/templates/default/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
1 change: 1 addition & 0 deletions packages/create-svelte/templates/skeleton/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package