diff --git a/.changeset/blue-goats-end.md b/.changeset/blue-goats-end.md new file mode 100644 index 000000000..7d3705a93 --- /dev/null +++ b/.changeset/blue-goats-end.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Removes mounting the project folder and adds a `src` root option diff --git a/docs/config.md b/docs/config.md index f3c2a60ce..c91970306 100644 --- a/docs/config.md +++ b/docs/config.md @@ -5,7 +5,8 @@ To configure Astro, add an `astro.config.mjs` file in the root of your project. ```js export default { projectRoot: '.', // Where to resolve all URLs relative to. Useful if you have a monorepo project. - pages: './src/pages', // Path to Astro components, pages, and data + src: './src', // Path to Astro components, pages, and data + pages: './src/pages', // Path to Astro/Markdown pages dist: './dist', // When running `astro build`, path to final static output public: './public', // A folder of static files Astro will copy to the root. Useful for favicons, images, and other files that don’t need processing. buildOptions: { diff --git a/packages/astro/components/Prism.astro b/packages/astro/components/Prism.astro index 674a6cc67..1d0703bba 100644 --- a/packages/astro/components/Prism.astro +++ b/packages/astro/components/Prism.astro @@ -1,7 +1,7 @@ --- import Prism from 'prismjs'; import { addAstro } from '@astrojs/prism'; -import * as loadLanguages from 'prismjs/components/index.js'; +import loadLanguages from 'prismjs/components/index.js'; export let lang; export let code; diff --git a/packages/astro/package.json b/packages/astro/package.json index b2b6c11fa..7f23f5f70 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -92,7 +92,7 @@ "sass": "^1.32.13", "shorthash": "^0.0.2", "slash": "^4.0.0", - "snowpack": "^3.5.9", + "snowpack": "^3.6.0", "source-map-support": "^0.5.19", "string-width": "^5.0.0", "tiny-glob": "^0.2.8", diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 448cee9c6..4e3d00f78 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -3,6 +3,7 @@ import type { ImportSpecifier, ImportDefaultSpecifier, ImportNamespaceSpecifier export interface AstroConfigRaw { dist: string; projectRoot: string; + src: string; pages: string; public: string; jsx?: string; @@ -19,6 +20,7 @@ export interface AstroConfig { projectRoot: URL; pages: URL; public: URL; + src: URL; renderers?: string[]; /** Options for rendering markdown content */ markdownOptions?: Partial; diff --git a/packages/astro/src/config.ts b/packages/astro/src/config.ts index 44e05107d..f4315aff6 100644 --- a/packages/astro/src/config.ts +++ b/packages/astro/src/config.ts @@ -54,6 +54,7 @@ function configDefaults(userConfig?: any): any { const config: any = { ...(userConfig || {}) }; if (!config.projectRoot) config.projectRoot = '.'; + if (!config.src) config.src = './src'; if (!config.pages) config.pages = './src/pages'; if (!config.dist) config.dist = './dist'; if (!config.public) config.public = './public'; @@ -72,6 +73,7 @@ function normalizeConfig(userConfig: any, root: string): AstroConfig { const fileProtocolRoot = `file://${root}/`; config.projectRoot = new URL(config.projectRoot + '/', fileProtocolRoot); + config.src = new URL(config.src + '/', fileProtocolRoot); config.pages = new URL(config.pages + '/', fileProtocolRoot); config.public = new URL(config.public + '/', fileProtocolRoot); diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 9b9629dc2..1b86b4ec8 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -308,7 +308,7 @@ interface CreateSnowpackOptions { /** Create a new Snowpack instance to power Astro */ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackOptions) { - const { projectRoot } = astroConfig; + const { projectRoot, src } = astroConfig; const { mode, resolvePackageUrl } = options; const frontendPath = new URL('./frontend/', import.meta.url); @@ -335,7 +335,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO const mountOptions = { ...(existsSync(astroConfig.public) ? { [fileURLToPath(astroConfig.public)]: '/' } : {}), [fileURLToPath(frontendPath)]: '/_astro_frontend', - [fileURLToPath(projectRoot)]: '/_astro', // must be last (greediest) + [fileURLToPath(src)]: '/_astro/src', // must be last (greediest) }; // Tailwind: IDK what this does but it makes JIT work 🤷‍♂️ @@ -345,7 +345,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO // Make sure that Snowpack builds our renderer plugins const rendererInstances = await configManager.buildRendererInstances(); - const knownEntrypoints: string[] = []; + const knownEntrypoints: string[] = ['astro/dist/internal/__astro_component.js']; for (const renderer of rendererInstances) { knownEntrypoints.push(renderer.server, renderer.client); if (renderer.knownEntrypoints) { diff --git a/yarn.lock b/yarn.lock index 8e9dcb2e4..3a34c18e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8940,10 +8940,10 @@ smartwrap@^1.2.3: wcwidth "^1.0.1" yargs "^15.1.0" -snowpack@^3.5.9: - version "3.5.9" - resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.5.9.tgz#c374c6b8633ec5baf8311adc964238edeea67b3b" - integrity sha512-Rajenx5DRDiMKC+GiU1vMP+tcjge9bAe35fGsPdhkTtIwRkV3u4he1TfiwTh8F1hcOcG5IzLe8jqGM9sBANtpw== +snowpack@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/snowpack/-/snowpack-3.6.0.tgz#4c1af4c760be88b1c65594f0fb90f57c99c2338d" + integrity sha512-MCRkA3+vJTBxVtb2nwoHETMunzo96l10VsgUuxHXvxsFaZqAkdT50bViuEyFv6fhEujMh55oSHY9pCrxGYA0aQ== dependencies: cli-spinners "^2.5.0" default-browser-id "^2.0.0"