Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change path into assets #5584

Merged
merged 7 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/lovely-worms-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astrojs/deno': major
'@astrojs/netlify': major
'@astrojs/image': minor
'astro': major
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
---

Builds chunks into the `assets` folder. This simplifies configuring immutable caching with your adapter provider as all files are now in the same `assets` folder.
4 changes: 2 additions & 2 deletions packages/astro/src/core/build/static-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ async function clientBuild(
input: Array.from(input),
output: {
format: 'esm',
entryFileNames: '[name].[hash].js',
chunkFileNames: 'chunks/[name].[hash].js',
entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/chunks/[name].[hash].js',
assetFileNames: 'assets/[name].[hash][extname]',
...viteConfig.build?.rollupOptions?.output,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/astro-dynamic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ describe('Dynamic components subpath', () => {
expect($('astro-island').html()).to.equal('');
// test 2: has component url
const attr = $('astro-island').attr('component-url');
expect(attr).to.include(`blog/PersistentCounter`);
expect(attr).to.include(`blog/assets/PersistentCounter`);
});
});
5 changes: 3 additions & 2 deletions packages/astro/test/astro-envs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ describe('Environment Variables', () => {
});

it('includes public env in client-side JS', async () => {
let dirs = await fixture.readdir('/');
let dirs = await fixture.readdir('/assets');
console.log(dirs)
let found = false;

// Look in all of the .js files to see if the public env is inlined.
Expand All @@ -61,7 +62,7 @@ describe('Environment Variables', () => {
await Promise.all(
dirs.map(async (path) => {
if (path.endsWith('.js')) {
let js = await fixture.readFile(`/${path}`);
let js = await fixture.readFile(`/assets/${path}`);
if (js.includes('BLUE_BAYOU')) {
found = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/sourcemap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Sourcemap', async () => {
});

it('Builds sourcemap', async () => {
const dir = await fixture.readdir('.');
const dir = await fixture.readdir('./assets');
const counterMap = dir.find((file) => file.match(/^Counter\.\w+\.js\.map$/));
expect(counterMap).to.be.ok;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
try {
const chunkFileNames =
_vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'chunks/chunk.[hash].mjs';
_vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'assets/chunks/chunk.[hash].mjs';
const chunkPath = npath.dirname(chunkFileNames);
const chunksDirUrl = new URL(chunkPath + '/', _buildConfig.server);
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true });
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/image/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
// For the Squoosh service, copy all wasm files to dist/chunks.
// Because the default loader is dynamically imported (above),
// Vite will bundle squoosh to dist/chunks and expect to find the wasm files there
await copyWasmFiles(new URL('./chunks', dir));
await copyWasmFiles(new URL('./assets/chunks', dir));
}

if (loader && 'transform' in loader && staticImages.size > 0) {
Expand All @@ -166,7 +166,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
},
'astro:build:ssr': async () => {
if (resolvedOptions.serviceEntryPoint === '@astrojs/image/squoosh') {
await copyWasmFiles(new URL('./chunks/', _buildConfig.server));
await copyWasmFiles(new URL('./assets/chunks/', _buildConfig.server));
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function bundleServerEntry({ serverEntry, server }: BuildConfig, vite: any
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
try {
const chunkFileNames =
vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'chunks/chunk.[hash].mjs';
vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'assets/chunks/chunk.[hash].mjs';
const chunkPath = npath.dirname(chunkFileNames);
const chunksDirUrl = new URL(chunkPath + '/', server);
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true });
Expand Down