Skip to content

Commit

Permalink
refactor dev to use vite server
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott committed Jan 29, 2022
1 parent dc412f6 commit 432577b
Show file tree
Hide file tree
Showing 21 changed files with 223 additions and 464 deletions.
7 changes: 7 additions & 0 deletions .changeset/empty-snails-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'astro': minor
---

Refactor dev server to use vite server internally.

This should be an invisible change, and no breaking changes are expected from this change. However, it is a big enough refactor that some unexpected changes may occur. If you've experienced a regression in the dev server, it is most likely a bug!
18 changes: 1 addition & 17 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,7 @@ SOFTWARE.


"""
This license applies to parts of the `packages/astro-parser` subdirectory originating from the
https://github.com/sveltejs/svelte repository:


Copyright (c) 2016-21 [these people](https://github.com/sveltejs/svelte/graphs/contributors)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""


"""
This license applies to parts of the `packages/create-astro` subdirectory originating from the
https://github.com/sveltejs/kit repository:
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:

Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)

Expand Down
1 change: 0 additions & 1 deletion packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"astring": "^1.7.5",
"ci-info": "^3.2.0",
"common-ancestor-path": "^1.0.1",
"connect": "^3.7.0",
"eol": "^0.9.1",
"es-module-lexer": "^0.9.3",
"esbuild": "0.13.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

import type { AstroConfig } from '../@types/astro';
import type { LogOptions } from '../core/logger';
import type { LogOptions } from '../core/logger.js';

import * as colors from 'kleur/colors';
import fs from 'fs';
Expand Down
12 changes: 6 additions & 6 deletions packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { AstroConfig } from '../@types/astro';
import type { AstroDevServer } from './dev';
import type { LogOptions } from './logger';

import { builtinModules } from 'module';
import { fileURLToPath } from 'url';
import vite from './vite.js';
import astroVitePlugin from '../vite-plugin-astro/index.js';
import astroViteServerPlugin from '../vite-plugin-astro-server/index.js';
import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.js';
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
Expand Down Expand Up @@ -34,12 +34,11 @@ export type ViteConfigWithSSR = vite.InlineConfig & { ssr?: { external?: string[

interface CreateViteOptions {
astroConfig: AstroConfig;
devServer?: AstroDevServer;
logging: LogOptions;
}

/** Return a common starting point for all Vite actions */
export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, logging, devServer }: CreateViteOptions): Promise<ViteConfigWithSSR> {
export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig, logging }: CreateViteOptions): Promise<ViteConfigWithSSR> {
// First, start with the Vite configuration that Astro core needs
let viteConfig: ViteConfigWithSSR = {
cacheDir: fileURLToPath(new URL('./node_modules/.vite/', astroConfig.projectRoot)), // using local caches allows Astro to be used in monorepos, etc.
Expand All @@ -50,10 +49,11 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig,
},
plugins: [
configAliasVitePlugin({ config: astroConfig }),
astroVitePlugin({ config: astroConfig, devServer, logging }),
markdownVitePlugin({ config: astroConfig, devServer }),
astroVitePlugin({ config: astroConfig, logging }),
astroViteServerPlugin({ config: astroConfig, logging }),
markdownVitePlugin({ config: astroConfig }),
jsxVitePlugin({ config: astroConfig, logging }),
astroPostprocessVitePlugin({ config: astroConfig, devServer }),
astroPostprocessVitePlugin({ config: astroConfig }),
],
publicDir: fileURLToPath(astroConfig.public),
root: fileURLToPath(astroConfig.projectRoot),
Expand Down
Loading

0 comments on commit 432577b

Please sign in to comment.