astro 0.25.2 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/astro.js +0 -0
- package/dist/@types/serialize-javascript.d.js +0 -0
- package/dist/@types/shorthash.d.js +0 -0
- package/dist/adapter-ssg/index.js +0 -0
- package/dist/cli/check.js +4 -4
- package/dist/cli/index.js +21 -32
- package/dist/core/add/babel.js +0 -0
- package/dist/core/add/consts.js +0 -0
- package/dist/core/add/imports.js +0 -0
- package/dist/core/add/index.js +7 -14
- package/dist/core/add/wrapper.js +0 -0
- package/dist/core/app/common.js +0 -0
- package/dist/core/app/index.js +13 -10
- package/dist/core/app/node.js +0 -0
- package/dist/core/app/types.js +0 -0
- package/dist/core/build/add-rollup-input.js +0 -0
- package/dist/core/build/common.js +4 -5
- package/dist/core/build/generate.js +65 -72
- package/dist/core/build/index.js +59 -74
- package/dist/core/build/internal.js +4 -0
- package/dist/core/build/page-data.js +10 -9
- package/dist/core/build/static-build.js +46 -28
- package/dist/core/build/types.d.js +0 -0
- package/dist/core/build/util.js +0 -0
- package/dist/core/build/vite-plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/vite-plugin-internals.js +0 -0
- package/dist/core/build/vite-plugin-pages.js +1 -0
- package/dist/core/build/vite-plugin-ssr.js +4 -2
- package/dist/core/config.js +87 -79
- package/dist/core/create-vite.js +12 -7
- package/dist/core/dev/index.js +8 -7
- package/dist/core/endpoint/dev/index.js +5 -10
- package/dist/core/endpoint/index.js +1 -3
- package/dist/core/errors.js +45 -0
- package/dist/core/logger/console.js +43 -0
- package/dist/core/logger/core.js +103 -0
- package/dist/core/logger/node.js +94 -0
- package/dist/core/messages.js +50 -24
- package/dist/core/path.js +0 -0
- package/dist/core/polyfill.js +0 -0
- package/dist/core/preview/index.js +8 -8
- package/dist/core/preview/util.js +3 -6
- package/dist/core/render/core.js +5 -6
- package/dist/core/render/dev/css.js +5 -6
- package/dist/core/render/dev/hmr.js +0 -0
- package/dist/core/render/dev/html.js +0 -0
- package/dist/core/render/dev/index.js +23 -36
- package/dist/core/render/paginate.js +0 -0
- package/dist/core/render/pretty-feed.js +103 -0
- package/dist/core/render/result.js +33 -15
- package/dist/core/render/route-cache.js +2 -2
- package/dist/core/render/rss.js +5 -4
- package/dist/core/render/script.js +0 -0
- package/dist/core/render/ssr-element.js +1 -1
- package/dist/core/render/util.js +26 -0
- package/dist/core/request.js +27 -0
- package/dist/core/routing/index.js +0 -0
- package/dist/core/routing/manifest/create.js +8 -6
- package/dist/core/routing/manifest/serialization.js +0 -0
- package/dist/core/routing/match.js +0 -0
- package/dist/core/routing/params.js +0 -0
- package/dist/core/routing/validation.js +1 -1
- package/dist/core/util.js +57 -125
- package/dist/integrations/index.js +9 -1
- package/dist/runtime/client/hmr.js +0 -0
- package/dist/runtime/client/idle.js +0 -0
- package/dist/runtime/client/load.js +0 -0
- package/dist/runtime/client/media.js +0 -0
- package/dist/runtime/client/only.js +0 -0
- package/dist/runtime/client/visible.js +0 -0
- package/dist/runtime/server/escape.js +0 -0
- package/dist/runtime/server/hydration.js +0 -0
- package/dist/runtime/server/index.js +42 -36
- package/dist/runtime/server/metadata.js +0 -0
- package/dist/runtime/server/util.js +0 -0
- package/dist/template/4xx.js +1 -1
- package/dist/template/5xx.js +0 -0
- package/dist/template/css.js +0 -0
- package/dist/types/@types/astro.d.ts +291 -233
- package/dist/types/cli/index.d.ts +1 -1
- package/dist/types/core/add/index.d.ts +1 -1
- package/dist/types/core/build/common.d.ts +0 -1
- package/dist/types/core/build/generate.d.ts +1 -1
- package/dist/types/core/build/index.d.ts +1 -1
- package/dist/types/core/build/internal.d.ts +1 -0
- package/dist/types/core/build/page-data.d.ts +1 -1
- package/dist/types/core/build/vite-plugin-pages.d.ts +1 -0
- package/dist/types/core/config.d.ts +125 -116
- package/dist/types/core/create-vite.d.ts +1 -1
- package/dist/types/core/dev/index.d.ts +1 -1
- package/dist/types/core/endpoint/index.d.ts +1 -1
- package/dist/types/core/errors.d.ts +23 -0
- package/dist/types/core/logger/console.d.ts +4 -0
- package/dist/types/core/{logger.d.ts → logger/core.d.ts} +7 -22
- package/dist/types/core/logger/node.d.ts +34 -0
- package/dist/types/core/messages.d.ts +4 -2
- package/dist/types/core/preview/index.d.ts +1 -1
- package/dist/types/core/preview/util.d.ts +1 -2
- package/dist/types/core/render/core.d.ts +2 -3
- package/dist/types/core/render/dev/css.d.ts +0 -2
- package/dist/types/core/render/dev/index.d.ts +4 -6
- package/dist/types/core/render/pretty-feed.d.ts +2 -0
- package/dist/types/core/render/result.d.ts +2 -3
- package/dist/types/core/render/route-cache.d.ts +1 -1
- package/dist/types/core/render/util.d.ts +6 -0
- package/dist/types/core/request.d.ts +14 -0
- package/dist/types/core/routing/manifest/create.d.ts +1 -1
- package/dist/types/core/routing/validation.d.ts +1 -1
- package/dist/types/core/util.d.ts +11 -7
- package/dist/types/integrations/index.d.ts +6 -0
- package/dist/types/runtime/server/index.d.ts +1 -2
- package/dist/types/vite-plugin-astro/hmr.d.ts +1 -1
- package/dist/types/vite-plugin-astro/index.d.ts +1 -1
- package/dist/types/vite-plugin-astro-server/index.d.ts +1 -1
- package/dist/types/vite-plugin-build-css/index.d.ts +2 -1
- package/dist/types/vite-plugin-build-html/extract-assets.d.ts +1 -1
- package/dist/types/vite-plugin-build-html/index.d.ts +3 -3
- package/dist/types/vite-plugin-config-alias/index.d.ts +1 -1
- package/dist/types/vite-plugin-jsx/index.d.ts +1 -1
- package/dist/vite-plugin-astro/compile.js +12 -14
- package/dist/vite-plugin-astro/hmr.js +2 -2
- package/dist/vite-plugin-astro/index.js +21 -8
- package/dist/vite-plugin-astro/query.js +0 -0
- package/dist/vite-plugin-astro/styles.js +1 -1
- package/dist/vite-plugin-astro-postprocess/index.js +31 -34
- package/dist/vite-plugin-astro-server/index.js +50 -22
- package/dist/vite-plugin-build-css/index.js +47 -4
- package/dist/vite-plugin-build-css/resolve.js +0 -0
- package/dist/vite-plugin-build-html/add-rollup-input.js +0 -0
- package/dist/vite-plugin-build-html/extract-assets.js +0 -0
- package/dist/vite-plugin-build-html/index.js +22 -23
- package/dist/vite-plugin-build-html/util.js +0 -0
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +1 -1
- package/dist/vite-plugin-integrations-container/index.js +0 -0
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +89 -18
- package/dist/vite-plugin-scripts/index.js +0 -0
- package/env.d.ts +1 -1
- package/package.json +13 -9
- package/dist/core/build/scan-based-build.js +0 -61
- package/dist/core/dev/util.js +0 -44
- package/dist/core/logger.js +0 -174
- package/dist/core/render/dev/error.js +0 -34
- package/dist/core/render/request.js +0 -23
- package/dist/core/render/sitemap.js +0 -18
- package/dist/types/core/build/scan-based-build.d.ts +0 -18
- package/dist/types/core/dev/util.d.ts +0 -9
- package/dist/types/core/render/dev/error.d.ts +0 -7
- package/dist/types/core/render/request.d.ts +0 -15
- package/dist/types/core/render/sitemap.d.ts +0 -2
package/dist/core/build/index.js
CHANGED
|
@@ -4,41 +4,39 @@ import { apply as applyPolyfill } from "../polyfill.js";
|
|
|
4
4
|
import { performance } from "perf_hooks";
|
|
5
5
|
import * as vite from "vite";
|
|
6
6
|
import { createVite } from "../create-vite.js";
|
|
7
|
-
import { debug,
|
|
7
|
+
import { debug, info, levels, timerMessage, warnIfUsingExperimentalSSR } from "../logger/core.js";
|
|
8
|
+
import { nodeLogOptions } from "../logger/node.js";
|
|
8
9
|
import { createRouteManifest } from "../routing/index.js";
|
|
9
|
-
import { generateSitemap } from "../render/sitemap.js";
|
|
10
10
|
import { collectPagesData } from "./page-data.js";
|
|
11
|
-
import { build as scanBasedBuild } from "./scan-based-build.js";
|
|
12
11
|
import { staticBuild } from "./static-build.js";
|
|
13
12
|
import { RouteCache } from "../render/route-cache.js";
|
|
14
13
|
import { runHookBuildDone, runHookBuildStart, runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
15
14
|
import { getTimeStat } from "./util.js";
|
|
16
|
-
|
|
15
|
+
import { createSafeError, isBuildingToSSR } from "../util.js";
|
|
16
|
+
import { fixViteErrorMessage } from "../errors.js";
|
|
17
|
+
async function build(config, options = { logging: nodeLogOptions }) {
|
|
18
|
+
applyPolyfill();
|
|
17
19
|
const builder = new AstroBuilder(config, options);
|
|
18
|
-
await builder.
|
|
20
|
+
await builder.run();
|
|
19
21
|
}
|
|
20
22
|
class AstroBuilder {
|
|
21
23
|
constructor(config, options) {
|
|
22
24
|
this.mode = "production";
|
|
23
|
-
|
|
24
|
-
if (!config.buildOptions.site && config.buildOptions.sitemap !== false) {
|
|
25
|
-
warn(options.logging, "config", `Set "buildOptions.site" to generate correct canonical URLs and sitemap`);
|
|
26
|
-
}
|
|
27
|
-
if (options.mode)
|
|
25
|
+
if (options.mode) {
|
|
28
26
|
this.mode = options.mode;
|
|
27
|
+
}
|
|
29
28
|
this.config = config;
|
|
30
|
-
const port = config.devOptions.port;
|
|
31
29
|
this.logging = options.logging;
|
|
32
30
|
this.routeCache = new RouteCache(this.logging);
|
|
33
|
-
this.origin = config.
|
|
31
|
+
this.origin = config.site ? new URL(config.site).origin : `http://localhost:${config.server.port}`;
|
|
34
32
|
this.manifest = createRouteManifest({ config }, this.logging);
|
|
33
|
+
this.timer = {};
|
|
35
34
|
}
|
|
36
|
-
async
|
|
37
|
-
|
|
38
|
-
const { logging
|
|
39
|
-
|
|
40
|
-
timer.
|
|
41
|
-
timer.viteStart = performance.now();
|
|
35
|
+
async setup() {
|
|
36
|
+
debug("build", "Initial setup...");
|
|
37
|
+
const { logging } = this;
|
|
38
|
+
this.timer.init = performance.now();
|
|
39
|
+
this.timer.viteStart = performance.now();
|
|
42
40
|
this.config = await runHookConfigSetup({ config: this.config, command: "build" });
|
|
43
41
|
const viteConfig = await createVite({
|
|
44
42
|
mode: this.mode,
|
|
@@ -49,66 +47,55 @@ class AstroBuilder {
|
|
|
49
47
|
}, { astroConfig: this.config, logging, mode: "build" });
|
|
50
48
|
await runHookConfigDone({ config: this.config });
|
|
51
49
|
warnIfUsingExperimentalSSR(logging, this.config);
|
|
52
|
-
this.viteConfig = viteConfig;
|
|
53
50
|
const viteServer = await vite.createServer(viteConfig);
|
|
54
|
-
this.
|
|
55
|
-
|
|
51
|
+
debug("build", timerMessage("Vite started", this.timer.viteStart));
|
|
52
|
+
return { viteConfig, viteServer };
|
|
53
|
+
}
|
|
54
|
+
async build({ viteConfig, viteServer }) {
|
|
55
|
+
const { origin } = this;
|
|
56
56
|
const buildConfig = {
|
|
57
|
-
client: new URL("./client/", this.config.
|
|
58
|
-
server: new URL("./server/", this.config.
|
|
57
|
+
client: new URL("./client/", this.config.outDir),
|
|
58
|
+
server: new URL("./server/", this.config.outDir),
|
|
59
59
|
serverEntry: "entry.mjs",
|
|
60
60
|
staticMode: void 0
|
|
61
61
|
};
|
|
62
62
|
await runHookBuildStart({ config: this.config, buildConfig });
|
|
63
|
-
info(this.logging, "build", "Collecting
|
|
64
|
-
timer.loadStart = performance.now();
|
|
63
|
+
info(this.logging, "build", "Collecting build information...");
|
|
64
|
+
this.timer.loadStart = performance.now();
|
|
65
65
|
const { assets, allPages } = await collectPagesData({
|
|
66
66
|
astroConfig: this.config,
|
|
67
67
|
logging: this.logging,
|
|
68
68
|
manifest: this.manifest,
|
|
69
69
|
origin,
|
|
70
70
|
routeCache: this.routeCache,
|
|
71
|
-
viteServer
|
|
72
|
-
ssr: this.config
|
|
71
|
+
viteServer,
|
|
72
|
+
ssr: isBuildingToSSR(this.config)
|
|
73
73
|
});
|
|
74
74
|
Object.entries(allPages).forEach(([page, data]) => {
|
|
75
75
|
if ("frontmatter" in data.preload[1]) {
|
|
76
76
|
const frontmatter = data.preload[1].frontmatter;
|
|
77
|
-
if (Boolean(frontmatter.draft) && !this.config.
|
|
78
|
-
debug("build", timerMessage(`Skipping draft page ${page}`, timer.loadStart));
|
|
77
|
+
if (Boolean(frontmatter.draft) && !this.config.markdown.drafts) {
|
|
78
|
+
debug("build", timerMessage(`Skipping draft page ${page}`, this.timer.loadStart));
|
|
79
79
|
delete allPages[page];
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
debug("build", timerMessage("All pages loaded", timer.loadStart));
|
|
83
|
+
debug("build", timerMessage("All pages loaded", this.timer.loadStart));
|
|
84
84
|
const pageNames = [];
|
|
85
|
-
timer.buildStart = performance.now();
|
|
86
|
-
info(this.logging, "build", colors.dim(`Completed in ${getTimeStat(timer.init, performance.now())}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
await scanBasedBuild({
|
|
101
|
-
allPages,
|
|
102
|
-
astroConfig: this.config,
|
|
103
|
-
logging: this.logging,
|
|
104
|
-
origin: this.origin,
|
|
105
|
-
pageNames,
|
|
106
|
-
routeCache: this.routeCache,
|
|
107
|
-
viteConfig: this.viteConfig,
|
|
108
|
-
viteServer: this.viteServer
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
timer.assetsStart = performance.now();
|
|
85
|
+
this.timer.buildStart = performance.now();
|
|
86
|
+
info(this.logging, "build", colors.dim(`Completed in ${getTimeStat(this.timer.init, performance.now())}.`));
|
|
87
|
+
await staticBuild({
|
|
88
|
+
allPages,
|
|
89
|
+
astroConfig: this.config,
|
|
90
|
+
logging: this.logging,
|
|
91
|
+
manifest: this.manifest,
|
|
92
|
+
origin: this.origin,
|
|
93
|
+
pageNames,
|
|
94
|
+
routeCache: this.routeCache,
|
|
95
|
+
viteConfig,
|
|
96
|
+
buildConfig
|
|
97
|
+
});
|
|
98
|
+
this.timer.assetsStart = performance.now();
|
|
112
99
|
Object.keys(assets).map((k) => {
|
|
113
100
|
if (!assets[k])
|
|
114
101
|
return;
|
|
@@ -117,21 +104,21 @@ class AstroBuilder {
|
|
|
117
104
|
fs.writeFileSync(filePath, assets[k], "utf8");
|
|
118
105
|
delete assets[k];
|
|
119
106
|
});
|
|
120
|
-
debug("build", timerMessage("Additional assets copied", timer.assetsStart));
|
|
121
|
-
if (this.config.buildOptions.sitemap && this.config.buildOptions.site) {
|
|
122
|
-
timer.sitemapStart = performance.now();
|
|
123
|
-
const sitemapFilter = this.config.buildOptions.sitemapFilter ? this.config.buildOptions.sitemapFilter : void 0;
|
|
124
|
-
const sitemap = generateSitemap(pageNames.map((pageName) => new URL(pageName, this.config.buildOptions.site).href), sitemapFilter);
|
|
125
|
-
const sitemapPath = new URL("./sitemap.xml", this.config.dist);
|
|
126
|
-
await fs.promises.mkdir(new URL("./", sitemapPath), { recursive: true });
|
|
127
|
-
await fs.promises.writeFile(sitemapPath, sitemap, "utf8");
|
|
128
|
-
debug("build", timerMessage("Sitemap built", timer.sitemapStart));
|
|
129
|
-
}
|
|
107
|
+
debug("build", timerMessage("Additional assets copied", this.timer.assetsStart));
|
|
130
108
|
await viteServer.close();
|
|
131
109
|
await runHookBuildDone({ config: this.config, pages: pageNames, routes: Object.values(allPages).map((pd) => pd.route) });
|
|
132
|
-
if (logging.level && levels[logging.level] <= levels["info"]) {
|
|
133
|
-
const buildMode = this.config
|
|
134
|
-
await this.printStats({ logging, timeStart: timer.init, pageCount: pageNames.length, buildMode });
|
|
110
|
+
if (this.logging.level && levels[this.logging.level] <= levels["info"]) {
|
|
111
|
+
const buildMode = isBuildingToSSR(this.config) ? "ssr" : "static";
|
|
112
|
+
await this.printStats({ logging: this.logging, timeStart: this.timer.init, pageCount: pageNames.length, buildMode });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async run() {
|
|
116
|
+
const setupData = await this.setup();
|
|
117
|
+
try {
|
|
118
|
+
await this.build(setupData);
|
|
119
|
+
} catch (_err) {
|
|
120
|
+
debugger;
|
|
121
|
+
throw fixViteErrorMessage(createSafeError(_err), setupData.viteServer);
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
async printStats({ logging, timeStart, pageCount, buildMode }) {
|
|
@@ -139,14 +126,12 @@ class AstroBuilder {
|
|
|
139
126
|
const total = getTimeStat(timeStart, performance.now());
|
|
140
127
|
let messages = [];
|
|
141
128
|
if (buildMode === "static") {
|
|
142
|
-
|
|
143
|
-
const perPageMsg = colors.dim(`(${colors.bold(`${timePerPage}ms`)} avg per page + resources)`);
|
|
144
|
-
messages = [`${pageCount} pages built in`, colors.bold(total), perPageMsg];
|
|
129
|
+
messages = [`${pageCount} page(s) built in`, colors.bold(total)];
|
|
145
130
|
} else {
|
|
146
131
|
messages = ["Server built in", colors.bold(total)];
|
|
147
132
|
}
|
|
148
133
|
info(logging, "build", messages.join(" "));
|
|
149
|
-
info(logging, "build",
|
|
134
|
+
info(logging, "build", `${colors.bold("Complete!")}`);
|
|
150
135
|
}
|
|
151
136
|
}
|
|
152
137
|
export {
|
|
@@ -41,6 +41,9 @@ function getPageDataByViteID(internals, viteid) {
|
|
|
41
41
|
}
|
|
42
42
|
return void 0;
|
|
43
43
|
}
|
|
44
|
+
function hasPageDataByViteID(internals, viteid) {
|
|
45
|
+
return internals.pagesByViteID.has(viteid);
|
|
46
|
+
}
|
|
44
47
|
function* eachPageData(internals) {
|
|
45
48
|
yield* internals.pagesByComponent.values();
|
|
46
49
|
}
|
|
@@ -50,5 +53,6 @@ export {
|
|
|
50
53
|
getPageDataByComponent,
|
|
51
54
|
getPageDataByViteID,
|
|
52
55
|
getPageDatasByChunk,
|
|
56
|
+
hasPageDataByViteID,
|
|
53
57
|
trackPageData
|
|
54
58
|
};
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { info } from "../logger.js";
|
|
1
|
+
import { info } from "../logger/core.js";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import * as colors from "kleur/colors";
|
|
4
|
-
import { debug } from "../logger.js";
|
|
4
|
+
import { debug } from "../logger/core.js";
|
|
5
5
|
import { preload as ssrPreload } from "../render/dev/index.js";
|
|
6
6
|
import { generateRssFunction } from "../render/rss.js";
|
|
7
7
|
import { callGetStaticPaths } from "../render/route-cache.js";
|
|
8
|
+
import { isBuildingToSSR } from "../util.js";
|
|
8
9
|
async function collectPagesData(opts) {
|
|
9
10
|
var _a;
|
|
10
11
|
const { astroConfig, logging, manifest, origin, routeCache, viteServer } = opts;
|
|
11
12
|
const assets = {};
|
|
12
13
|
const allPages = {};
|
|
13
|
-
const buildMode = astroConfig
|
|
14
|
+
const buildMode = isBuildingToSSR(astroConfig) ? "ssr" : "static";
|
|
14
15
|
const dataCollectionLogTimeout = setInterval(() => {
|
|
15
16
|
info(opts.logging, "build", "The data collection step may take longer for larger projects...");
|
|
16
17
|
clearInterval(dataCollectionLogTimeout);
|
|
@@ -31,7 +32,7 @@ async function collectPagesData(opts) {
|
|
|
31
32
|
scripts: /* @__PURE__ */ new Set(),
|
|
32
33
|
preload: await ssrPreload({
|
|
33
34
|
astroConfig,
|
|
34
|
-
filePath: new URL(`./${route.component}`, astroConfig.
|
|
35
|
+
filePath: new URL(`./${route.component}`, astroConfig.root),
|
|
35
36
|
viteServer
|
|
36
37
|
}).then((routes) => {
|
|
37
38
|
clearInterval(routeCollectionLogTimeout);
|
|
@@ -58,13 +59,13 @@ async function collectPagesData(opts) {
|
|
|
58
59
|
debug("build", `\u251C\u2500\u2500 ${colors.bold(colors.red("\u2717"))} ${route.component}`);
|
|
59
60
|
throw err;
|
|
60
61
|
});
|
|
61
|
-
const rssFn = generateRssFunction(astroConfig.
|
|
62
|
+
const rssFn = generateRssFunction(astroConfig.site, route);
|
|
62
63
|
for (const rssCallArg of result.rss) {
|
|
63
64
|
const rssResult = rssFn(rssCallArg);
|
|
64
65
|
if (rssResult.xml) {
|
|
65
66
|
const { url, content } = rssResult.xml;
|
|
66
67
|
if (content) {
|
|
67
|
-
const rssFile = new URL(url.replace(/^\/?/, "./"), astroConfig.
|
|
68
|
+
const rssFile = new URL(url.replace(/^\/?/, "./"), astroConfig.outDir);
|
|
68
69
|
if (assets[fileURLToPath(rssFile)]) {
|
|
69
70
|
throw new Error(`[getStaticPaths] RSS feed ${url} already exists.
|
|
70
71
|
Use \`rss(data, {url: '...'})\` to choose a unique, custom URL. (${route.component})`);
|
|
@@ -74,7 +75,7 @@ Use \`rss(data, {url: '...'})\` to choose a unique, custom URL. (${route.compone
|
|
|
74
75
|
}
|
|
75
76
|
if ((_a = rssResult.xsl) == null ? void 0 : _a.content) {
|
|
76
77
|
const { url, content } = rssResult.xsl;
|
|
77
|
-
const stylesheetFile = new URL(url.replace(/^\/?/, "./"), astroConfig.
|
|
78
|
+
const stylesheetFile = new URL(url.replace(/^\/?/, "./"), astroConfig.outDir);
|
|
78
79
|
if (assets[fileURLToPath(stylesheetFile)]) {
|
|
79
80
|
throw new Error(`[getStaticPaths] RSS feed stylesheet ${url} already exists.
|
|
80
81
|
Use \`rss(data, {stylesheet: '...'})\` to choose a unique, custom URL. (${route.component})`);
|
|
@@ -93,7 +94,7 @@ Use \`rss(data, {stylesheet: '...'})\` to choose a unique, custom URL. (${route.
|
|
|
93
94
|
scripts: /* @__PURE__ */ new Set(),
|
|
94
95
|
preload: await ssrPreload({
|
|
95
96
|
astroConfig,
|
|
96
|
-
filePath: new URL(`./${route.component}`, astroConfig.
|
|
97
|
+
filePath: new URL(`./${route.component}`, astroConfig.root),
|
|
97
98
|
viteServer
|
|
98
99
|
})
|
|
99
100
|
};
|
|
@@ -105,7 +106,7 @@ async function getStaticPathsForRoute(opts, route) {
|
|
|
105
106
|
const { astroConfig, logging, routeCache, ssr, viteServer } = opts;
|
|
106
107
|
if (!viteServer)
|
|
107
108
|
throw new Error(`vite.createServer() not called!`);
|
|
108
|
-
const filePath = new URL(`./${route.component}`, astroConfig.
|
|
109
|
+
const filePath = new URL(`./${route.component}`, astroConfig.root);
|
|
109
110
|
const mod = await viteServer.ssrLoadModule(fileURLToPath(filePath));
|
|
110
111
|
const result = await callGetStaticPaths({ mod, route, isValidate: false, logging, ssr });
|
|
111
112
|
routeCache.set(route, result);
|
|
@@ -24,8 +24,8 @@ import npath from "path";
|
|
|
24
24
|
import { fileURLToPath } from "url";
|
|
25
25
|
import * as vite from "vite";
|
|
26
26
|
import { createBuildInternals } from "../../core/build/internal.js";
|
|
27
|
-
import { info } from "
|
|
28
|
-
import {
|
|
27
|
+
import { info } from "../logger/core.js";
|
|
28
|
+
import { prependForwardSlash } from "../../core/path.js";
|
|
29
29
|
import { emptyDir, removeDir } from "../../core/util.js";
|
|
30
30
|
import { rollupPluginAstroBuildCSS } from "../../vite-plugin-build-css/index.js";
|
|
31
31
|
import { vitePluginHoistedScripts } from "./vite-plugin-hoisted-scripts.js";
|
|
@@ -35,6 +35,7 @@ import { vitePluginPages } from "./vite-plugin-pages.js";
|
|
|
35
35
|
import { generatePages } from "./generate.js";
|
|
36
36
|
import { trackPageData } from "./internal.js";
|
|
37
37
|
import { isBuildingToSSR } from "../util.js";
|
|
38
|
+
import { runHookBuildSetup } from "../../integrations/index.js";
|
|
38
39
|
import { getTimeStat } from "./util.js";
|
|
39
40
|
async function staticBuild(opts) {
|
|
40
41
|
const { allPages, astroConfig } = opts;
|
|
@@ -44,9 +45,8 @@ async function staticBuild(opts) {
|
|
|
44
45
|
const internals = createBuildInternals();
|
|
45
46
|
const timer = {};
|
|
46
47
|
timer.buildStart = performance.now();
|
|
47
|
-
info(opts.logging, "build", "Discovering entrypoints...");
|
|
48
48
|
for (const [component, pageData] of Object.entries(allPages)) {
|
|
49
|
-
const astroModuleURL = new URL("./" + component, astroConfig.
|
|
49
|
+
const astroModuleURL = new URL("./" + component, astroConfig.root);
|
|
50
50
|
const astroModuleId = prependForwardSlash(component);
|
|
51
51
|
trackPageData(internals, component, pageData, astroModuleId, astroModuleURL);
|
|
52
52
|
if (pageData.route.type === "page") {
|
|
@@ -71,13 +71,13 @@ async function staticBuild(opts) {
|
|
|
71
71
|
pageInput.add(astroModuleId);
|
|
72
72
|
facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
|
|
73
73
|
}
|
|
74
|
-
emptyDir(astroConfig.
|
|
74
|
+
emptyDir(astroConfig.outDir, new Set(".git"));
|
|
75
75
|
timer.clientBuild = performance.now();
|
|
76
76
|
await clientBuild(opts, internals, jsInput);
|
|
77
77
|
timer.ssr = performance.now();
|
|
78
78
|
info(opts.logging, "build", "Building for SSR...");
|
|
79
79
|
const ssrResult = await ssrBuild(opts, internals, pageInput);
|
|
80
|
-
info(opts.logging, "build", dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}
|
|
80
|
+
info(opts.logging, "build", dim(`Completed in ${getTimeStat(timer.ssr, performance.now())}.`));
|
|
81
81
|
timer.generate = performance.now();
|
|
82
82
|
if (opts.buildConfig.staticMode) {
|
|
83
83
|
await generatePages(ssrResult, opts, internals, facadeIdToPageDataMap);
|
|
@@ -88,14 +88,12 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
88
88
|
`);
|
|
89
89
|
await ssrMoveAssets(opts);
|
|
90
90
|
}
|
|
91
|
-
info(opts.logging, null, dim(`Completed in ${getTimeStat(timer.generate, performance.now())}
|
|
92
|
-
`));
|
|
93
91
|
}
|
|
94
92
|
async function ssrBuild(opts, internals, input) {
|
|
95
93
|
const { astroConfig, viteConfig } = opts;
|
|
96
|
-
const ssr = astroConfig
|
|
97
|
-
const out = ssr ? opts.buildConfig.server : astroConfig.
|
|
98
|
-
|
|
94
|
+
const ssr = isBuildingToSSR(astroConfig);
|
|
95
|
+
const out = ssr ? opts.buildConfig.server : astroConfig.outDir;
|
|
96
|
+
const viteBuildConfig = {
|
|
99
97
|
logLevel: "error",
|
|
100
98
|
mode: "production",
|
|
101
99
|
css: viteConfig.css,
|
|
@@ -103,17 +101,16 @@ async function ssrBuild(opts, internals, input) {
|
|
|
103
101
|
emptyOutDir: false,
|
|
104
102
|
manifest: false,
|
|
105
103
|
outDir: fileURLToPath(out),
|
|
106
|
-
ssr: true,
|
|
107
104
|
rollupOptions: {
|
|
108
105
|
input: [],
|
|
109
106
|
output: {
|
|
110
107
|
format: "esm",
|
|
111
108
|
entryFileNames: opts.buildConfig.serverEntry,
|
|
112
109
|
chunkFileNames: "chunks/chunk.[hash].mjs",
|
|
113
|
-
assetFileNames: "assets/asset.[hash][extname]"
|
|
114
|
-
inlineDynamicImports: true
|
|
110
|
+
assetFileNames: "assets/asset.[hash][extname]"
|
|
115
111
|
}
|
|
116
112
|
},
|
|
113
|
+
ssr: true,
|
|
117
114
|
target: "esnext",
|
|
118
115
|
minify: false,
|
|
119
116
|
polyfillModulePreload: false,
|
|
@@ -123,7 +120,8 @@ async function ssrBuild(opts, internals, input) {
|
|
|
123
120
|
vitePluginInternals(input, internals),
|
|
124
121
|
vitePluginPages(opts, internals),
|
|
125
122
|
rollupPluginAstroBuildCSS({
|
|
126
|
-
internals
|
|
123
|
+
internals,
|
|
124
|
+
legacy: false
|
|
127
125
|
}),
|
|
128
126
|
...viteConfig.plugins || [],
|
|
129
127
|
isBuildingToSSR(opts.astroConfig) && vitePluginSSR(opts, internals, opts.astroConfig._ctx.adapter)
|
|
@@ -132,21 +130,27 @@ async function ssrBuild(opts, internals, input) {
|
|
|
132
130
|
root: viteConfig.root,
|
|
133
131
|
envPrefix: "PUBLIC_",
|
|
134
132
|
server: viteConfig.server,
|
|
135
|
-
base: astroConfig.
|
|
136
|
-
ssr: viteConfig.ssr
|
|
137
|
-
|
|
133
|
+
base: astroConfig.site ? new URL(astroConfig.site).pathname : "/",
|
|
134
|
+
ssr: viteConfig.ssr,
|
|
135
|
+
resolve: viteConfig.resolve
|
|
136
|
+
};
|
|
137
|
+
await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: "server" });
|
|
138
|
+
return await vite.build(viteBuildConfig);
|
|
138
139
|
}
|
|
139
140
|
async function clientBuild(opts, internals, input) {
|
|
140
141
|
const { astroConfig, viteConfig } = opts;
|
|
141
142
|
const timer = performance.now();
|
|
143
|
+
const ssr = isBuildingToSSR(astroConfig);
|
|
144
|
+
const out = ssr ? opts.buildConfig.client : astroConfig.outDir;
|
|
142
145
|
if (!input.size) {
|
|
146
|
+
if (ssr) {
|
|
147
|
+
await copyFiles(astroConfig.publicDir, out);
|
|
148
|
+
}
|
|
143
149
|
return null;
|
|
144
150
|
}
|
|
145
151
|
info(opts.logging, null, `
|
|
146
|
-
${bgGreen(black(" building
|
|
147
|
-
|
|
148
|
-
const out = isBuildingToSSR(astroConfig) ? opts.buildConfig.client : astroConfig.dist;
|
|
149
|
-
const buildResult = await vite.build({
|
|
152
|
+
${bgGreen(black(" building client "))}`);
|
|
153
|
+
const viteBuildConfig = {
|
|
150
154
|
logLevel: "info",
|
|
151
155
|
mode: "production",
|
|
152
156
|
css: viteConfig.css,
|
|
@@ -170,7 +174,8 @@ ${bgGreen(black(" building resources "))}
|
|
|
170
174
|
vitePluginInternals(input, internals),
|
|
171
175
|
vitePluginHoistedScripts(astroConfig, internals),
|
|
172
176
|
rollupPluginAstroBuildCSS({
|
|
173
|
-
internals
|
|
177
|
+
internals,
|
|
178
|
+
legacy: false
|
|
174
179
|
}),
|
|
175
180
|
...viteConfig.plugins || []
|
|
176
181
|
],
|
|
@@ -178,21 +183,34 @@ ${bgGreen(black(" building resources "))}
|
|
|
178
183
|
root: viteConfig.root,
|
|
179
184
|
envPrefix: "PUBLIC_",
|
|
180
185
|
server: viteConfig.server,
|
|
181
|
-
base:
|
|
182
|
-
}
|
|
183
|
-
|
|
186
|
+
base: astroConfig.base
|
|
187
|
+
};
|
|
188
|
+
await runHookBuildSetup({ config: astroConfig, vite: viteBuildConfig, target: "client" });
|
|
189
|
+
const buildResult = await vite.build(viteBuildConfig);
|
|
190
|
+
info(opts.logging, null, dim(`Completed in ${getTimeStat(timer, performance.now())}.
|
|
184
191
|
`));
|
|
185
192
|
return buildResult;
|
|
186
193
|
}
|
|
187
194
|
async function cleanSsrOutput(opts) {
|
|
188
195
|
const files = await glob("**/*.mjs", {
|
|
189
|
-
cwd: fileURLToPath(opts.astroConfig.
|
|
196
|
+
cwd: fileURLToPath(opts.astroConfig.outDir)
|
|
190
197
|
});
|
|
191
198
|
await Promise.all(files.map(async (filename) => {
|
|
192
|
-
const url = new URL(filename, opts.astroConfig.
|
|
199
|
+
const url = new URL(filename, opts.astroConfig.outDir);
|
|
193
200
|
await fs.promises.rm(url);
|
|
194
201
|
}));
|
|
195
202
|
}
|
|
203
|
+
async function copyFiles(fromFolder, toFolder) {
|
|
204
|
+
const files = await glob("**/*", {
|
|
205
|
+
cwd: fileURLToPath(fromFolder)
|
|
206
|
+
});
|
|
207
|
+
await fs.promises.mkdir(toFolder, { recursive: true });
|
|
208
|
+
await Promise.all(files.map(async (filename) => {
|
|
209
|
+
const from = new URL(filename, fromFolder);
|
|
210
|
+
const to = new URL(filename, toFolder);
|
|
211
|
+
return fs.promises.copyFile(from, to);
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
196
214
|
async function ssrMoveAssets(opts) {
|
|
197
215
|
info(opts.logging, "build", "Rearranging server assets...");
|
|
198
216
|
const serverRoot = opts.buildConfig.staticMode ? opts.buildConfig.client : opts.buildConfig.server;
|
|
File without changes
|
package/dist/core/build/util.js
CHANGED
|
File without changes
|
|
@@ -28,7 +28,7 @@ function vitePluginHoistedScripts(astroConfig, internals) {
|
|
|
28
28
|
if (output.type === "chunk" && output.facadeModuleId && virtualHoistedEntry(output.facadeModuleId)) {
|
|
29
29
|
const facadeId = output.facadeModuleId;
|
|
30
30
|
const pathname = facadeId.slice(0, facadeId.length - "/hoisted.js".length);
|
|
31
|
-
const vid = viteID(new URL("." + pathname, astroConfig.
|
|
31
|
+
const vid = viteID(new URL("." + pathname, astroConfig.root));
|
|
32
32
|
const pageInfo = getPageDataByViteID(internals, vid);
|
|
33
33
|
if (pageInfo) {
|
|
34
34
|
pageInfo.hoistedScript = id;
|
|
File without changes
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import astroRemark from "@astrojs/markdown-remark";
|
|
1
2
|
import { serializeRouteData } from "../routing/index.js";
|
|
2
3
|
import { eachPageData } from "./internal.js";
|
|
3
4
|
import { addRollupInput } from "./add-rollup-input.js";
|
|
@@ -9,6 +10,7 @@ const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
|
|
|
9
10
|
function vitePluginSSR(buildOpts, internals, adapter) {
|
|
10
11
|
return {
|
|
11
12
|
name: "@astrojs/vite-plugin-astro-ssr",
|
|
13
|
+
enforce: "post",
|
|
12
14
|
options(opts) {
|
|
13
15
|
return addRollupInput(opts, [virtualModuleId]);
|
|
14
16
|
},
|
|
@@ -73,9 +75,9 @@ function buildManifest(opts, internals) {
|
|
|
73
75
|
entryModules[BEFORE_HYDRATION_SCRIPT_ID] = "data:text/javascript;charset=utf-8,//[no before-hydration script]";
|
|
74
76
|
const ssrManifest = {
|
|
75
77
|
routes,
|
|
76
|
-
site: astroConfig.
|
|
78
|
+
site: astroConfig.site,
|
|
77
79
|
markdown: {
|
|
78
|
-
render: astroConfig.
|
|
80
|
+
render: [astroRemark, astroConfig.markdown]
|
|
79
81
|
},
|
|
80
82
|
pageMap: null,
|
|
81
83
|
renderers: [],
|