summaryrefslogtreecommitdiff
path: root/packages/astro/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/astro/src')
-rw-r--r--packages/astro/src/build.ts2
-rw-r--r--packages/astro/src/build/bundle/css.ts8
-rw-r--r--packages/astro/src/build/bundle/js.ts6
-rw-r--r--packages/astro/src/build/util.ts6
-rw-r--r--packages/astro/src/runtime.ts2
5 files changed, 17 insertions, 7 deletions
diff --git a/packages/astro/src/build.ts b/packages/astro/src/build.ts
index 6f60c862a..28c9c90b7 100644
--- a/packages/astro/src/build.ts
+++ b/packages/astro/src/build.ts
@@ -149,7 +149,7 @@ ${stack}
astroRuntime.load(url).then((result) => {
if (result.statusCode !== 200) {
if (result.statusCode === 404) {
- throw new Error(`${buildState[id].srcPath.href}: could not find "${path.basename(url)}"`);
+ throw new Error(`${buildState[id].srcPath.href}: could not find "${url}"`);
}
// there shouldn’t be a build error here
throw (result as any).error || new Error(`unexpected status ${result.statusCode} when loading ${url}`);
diff --git a/packages/astro/src/build/bundle/css.ts b/packages/astro/src/build/bundle/css.ts
index 2cd59f24d..6da84da02 100644
--- a/packages/astro/src/build/bundle/css.ts
+++ b/packages/astro/src/build/bundle/css.ts
@@ -5,7 +5,7 @@ import { performance } from 'perf_hooks';
import shorthash from 'shorthash';
import cheerio from 'cheerio';
import esbuild from 'esbuild';
-import { getDistPath, getSrcPath, stopTimer } from '../util.js';
+import { getDistPath, getSrcPath, IS_ASTRO_FILE_URL, stopTimer } from '../util.js';
import { debug } from '../../logger.js';
// config
@@ -46,7 +46,9 @@ export async function bundleCSS({
for (const pageUrl of sortedPages) {
const { css } = depTree[pageUrl];
for (const cssUrl of css.keys()) {
- if (cssMap.has(cssUrl)) {
+ if (!IS_ASTRO_FILE_URL.test(cssUrl)) {
+ // do not add to cssMap, leave as-is.
+ } else if (cssMap.has(cssUrl)) {
// scenario 1: if multiple URLs require this CSS, upgrade to common chunk
cssMap.set(cssUrl, COMMON_URL);
} else {
@@ -83,7 +85,7 @@ export async function bundleCSS({
await Promise.all(
Object.keys(buildState).map(async (id) => {
if (buildState[id].contentType !== 'text/css') return;
- const { code } = await esbuild.transform(buildState[id].contents as string, {
+ const { code } = await esbuild.transform(buildState[id].contents.toString(), {
loader: 'css',
minify: true,
});
diff --git a/packages/astro/src/build/bundle/js.ts b/packages/astro/src/build/bundle/js.ts
index 7340d396b..4deecb30a 100644
--- a/packages/astro/src/build/bundle/js.ts
+++ b/packages/astro/src/build/bundle/js.ts
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'url';
import { rollup } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import { createBundleStats, addBundleStats, BundleStatsMap } from '../stats.js';
+import { IS_ASTRO_FILE_URL } from '../util.js';
interface BundleOptions {
dist: URL;
@@ -24,12 +25,13 @@ export function collectJSImports(buildState: BuildOutput): Set<string> {
/** Bundle JS action */
export async function bundleJS(imports: Set<string>, { astroRuntime, dist }: BundleOptions): Promise<BundleStatsMap> {
const ROOT = 'astro:root';
+ const validImports = [...imports].filter((url) => IS_ASTRO_FILE_URL.test(url));
const root = `
- ${[...imports].map((url) => `import '${url}';`).join('\n')}
+ ${validImports.map((url) => `import '${url}';`).join('\n')}
`;
const inputOptions: InputOptions = {
- input: [...imports],
+ input: validImports,
plugins: [
{
name: 'astro:build',
diff --git a/packages/astro/src/build/util.ts b/packages/astro/src/build/util.ts
index 3c74086e2..e3f2aaa17 100644
--- a/packages/astro/src/build/util.ts
+++ b/packages/astro/src/build/util.ts
@@ -5,6 +5,12 @@ import fs from 'fs';
import path from 'path';
import { URL } from 'url';
+/**
+ * Only Astro-handled imports need bundling. Any other imports are considered
+ * a part of `public/`, and should not be touched.
+ */
+export const IS_ASTRO_FILE_URL = /^\/(_astro|_astro_frontend|_snowpack)\//;
+
/** Normalize URL to its canonical form */
export function canonicalURL(url: string, base?: string): URL {
let pathname = url.replace(/\/index.html$/, ''); // index.html is not canonical
diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts
index 165df0a02..4145753ed 100644
--- a/packages/astro/src/runtime.ts
+++ b/packages/astro/src/runtime.ts
@@ -283,7 +283,7 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO
};
const mountOptions = {
- ...(existsSync(astroConfig.public) ? { [fileURLToPath(astroConfig.public)]: '/' } : {}),
+ ...(existsSync(astroConfig.public) ? { [fileURLToPath(astroConfig.public)]: { url: '/', static: true, resolve: false } } : {}),
[fileURLToPath(frontendPath)]: '/_astro_frontend',
[fileURLToPath(src)]: '/_astro/src', // must be last (greediest)
};