Replies: 6 comments 7 replies
-
I'm not really sure about this feature. I think it's good that Astro provides some opinion here so it's predictable and consistent with other projects. Astro also has specific directory names that you can't change today, e.g. |
Beta Was this translation helpful? Give feedback.
-
I would prefer to keep all source files that represent real UI pages in the "pages" directory for consistency across Astro projects. |
Beta Was this translation helpful? Give feedback.
-
Of course every team will have their preferences on what these directories should be called, but Astro does value providing strong and consist opinions on topics like this. For some context, when we landed on One thing that might be worth considering: instead of making |
Beta Was this translation helpful? Give feedback.
-
For future reference, there was a PR sent but was closed: withastro/astro#9503 |
Beta Was this translation helpful? Give feedback.
-
This is a useful feature if you want to dynamically change diff --git a/node_modules/astro/dist/core/build/css-asset-name.js b/node_modules/astro/dist/core/build/css-asset-name.js
index 35cea9d..2f9e8b3 100644
--- a/node_modules/astro/dist/core/build/css-asset-name.js
+++ b/node_modules/astro/dist/core/build/css-asset-name.js
@@ -21,8 +21,8 @@ function createNameHash(baseId, hashIds) {
return proposedName;
}
function createSlugger(settings) {
- const pagesDir = viteID(new URL("./pages", settings.config.srcDir));
- const indexPage = viteID(new URL("./pages/index", settings.config.srcDir));
+ const pagesDir = viteID(new URL(settings.config.pagesDir, settings.config.srcDir));
+ const indexPage = viteID(new URL(settings.config.pagesDir, settings.config.srcDir));
const map = /* @__PURE__ */ new Map();
const sep = "-";
return function(id, ctx) {
diff --git a/node_modules/astro/dist/core/config/schema.js b/node_modules/astro/dist/core/config/schema.js
index e0cd109..ca94bdd 100644
--- a/node_modules/astro/dist/core/config/schema.js
+++ b/node_modules/astro/dist/core/config/schema.js
@@ -9,6 +9,7 @@ const ASTRO_CONFIG_DEFAULTS = {
srcDir: "./src",
publicDir: "./public",
outDir: "./dist",
+ pagesDir: './pages',
cacheDir: "./node_modules/.astro",
base: "/",
trailingSlash: "ignore",
@@ -55,6 +56,7 @@ const AstroConfigSchema = z.object({
srcDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => new URL(val)),
publicDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => new URL(val)),
outDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => new URL(val)),
+ pagesDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.pagesDir).transform((val) => new URL(val)),
cacheDir: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => new URL(val)),
site: z.string().url().optional(),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
@@ -342,6 +344,7 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
root: z.string().default(ASTRO_CONFIG_DEFAULTS.root).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
srcDir: z.string().default(ASTRO_CONFIG_DEFAULTS.srcDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
compressHTML: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.compressHTML),
+ pagesDir: z.string().default(ASTRO_CONFIG_DEFAULTS.pagesDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
publicDir: z.string().default(ASTRO_CONFIG_DEFAULTS.publicDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
outDir: z.string().default(ASTRO_CONFIG_DEFAULTS.outDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
cacheDir: z.string().default(ASTRO_CONFIG_DEFAULTS.cacheDir).transform((val) => resolveDirAsUrl(val, fileProtocolRoot)),
diff --git a/node_modules/astro/dist/core/util.js b/node_modules/astro/dist/core/util.js
index 6d5ac94..a6d03de 100644
--- a/node_modules/astro/dist/core/util.js
+++ b/node_modules/astro/dist/core/util.js
@@ -64,7 +64,7 @@ function unwrapId(id) {
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
}
function resolvePages(config) {
- return new URL("./pages", config.srcDir);
+ return new URL(config.pagesDir, config.srcDir);
}
function isInPagesDir(file, config) {
const pagesDir = resolvePages(config); |
Beta Was this translation helpful? Give feedback.
-
I would like to advocate for this feature too. There is a frontend architecture methodology called Feature-Sliced Design (which I'm the maintainer of) and it has a concept of layers (folders) with standardized names. One of these names is Frameworks like Next.js, Remix, SvelteKit, and Nuxt.js also run up against this conflict, but there are ways to reconfigure the page directory to something like I think Astro's guidelines on project structure are very nice to have, but they should be opt-out-able, when you have a more comprehensive architectural solution to put in their place. |
Beta Was this translation helpful? Give feedback.
-
Body
Currently Astro Pages are
src/pages
directory and there's no way to change it. It would be nice to be able to change it with apagesDir
config option.Summary
Let's get a
pagesDir
option.Background & Motivation
I'm using Astro as a backend as well in a project, where it makes less sense to have it named
pages
and more sense to call themroutes
on backend. I'm basically getting file based routing for creating endpoints without any frontend code. It just works and makes more sense, creates less clutter.Goals
Beta Was this translation helpful? Give feedback.
All reactions