0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

feat: change path into assets (#5584)

* feat: change path

* feat: fix bug #5502

* fix: astro fix to patch

* feat: change to major

* chore: update changelog

* fix: change entryFileNames into assets folder

* fix: fix error message in test

Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
wulinsheng123 2023-01-06 00:41:10 +08:00 committed by GitHub
parent f1da0da29f
commit 9963c6e4d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 10 deletions

View file

@ -0,0 +1,8 @@
---
'@astrojs/deno': major
'@astrojs/netlify': major
'@astrojs/image': minor
'astro': major
---
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.

View file

@ -212,8 +212,8 @@ async function clientBuild(
input: Array.from(input), input: Array.from(input),
output: { output: {
format: 'esm', format: 'esm',
entryFileNames: '[name].[hash].js', entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'chunks/[name].[hash].js', chunkFileNames: 'assets/chunks/[name].[hash].js',
assetFileNames: 'assets/[name].[hash][extname]', assetFileNames: 'assets/[name].[hash][extname]',
...viteConfig.build?.rollupOptions?.output, ...viteConfig.build?.rollupOptions?.output,
}, },

View file

@ -75,6 +75,6 @@ describe('Dynamic components subpath', () => {
expect($('astro-island').html()).to.equal(''); expect($('astro-island').html()).to.equal('');
// test 2: has component url // test 2: has component url
const attr = $('astro-island').attr('component-url'); const attr = $('astro-island').attr('component-url');
expect(attr).to.include(`blog/PersistentCounter`); expect(attr).to.include(`blog/assets/PersistentCounter`);
}); });
}); });

View file

@ -52,7 +52,8 @@ describe('Environment Variables', () => {
}); });
it('includes public env in client-side JS', async () => { 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; let found = false;
// Look in all of the .js files to see if the public env is inlined. // Look in all of the .js files to see if the public env is inlined.
@ -61,7 +62,7 @@ describe('Environment Variables', () => {
await Promise.all( await Promise.all(
dirs.map(async (path) => { dirs.map(async (path) => {
if (path.endsWith('.js')) { if (path.endsWith('.js')) {
let js = await fixture.readFile(`/${path}`); let js = await fixture.readFile(`/assets/${path}`);
if (js.includes('BLUE_BAYOU')) { if (js.includes('BLUE_BAYOU')) {
found = true; found = true;
} }

View file

@ -10,7 +10,7 @@ describe('Sourcemap', async () => {
}); });
it('Builds 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$/)); const counterMap = dir.find((file) => file.match(/^Counter\.\w+\.js\.map$/));
expect(counterMap).to.be.ok; expect(counterMap).to.be.ok;
}); });

View file

@ -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. // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
try { try {
const chunkFileNames = 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 chunkPath = npath.dirname(chunkFileNames);
const chunksDirUrl = new URL(chunkPath + '/', _buildConfig.server); const chunksDirUrl = new URL(chunkPath + '/', _buildConfig.server);
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true }); await fs.promises.rm(chunksDirUrl, { recursive: true, force: true });

View file

@ -146,7 +146,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
// For the Squoosh service, copy all wasm files to dist/chunks. // For the Squoosh service, copy all wasm files to dist/chunks.
// Because the default loader is dynamically imported (above), // Because the default loader is dynamically imported (above),
// Vite will bundle squoosh to dist/chunks and expect to find the wasm files there // 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) { if (loader && 'transform' in loader && staticImages.size > 0) {
@ -166,7 +166,7 @@ export default function integration(options: IntegrationOptions = {}): AstroInte
}, },
'astro:build:ssr': async () => { 'astro:build:ssr': async () => {
if (resolvedOptions.serviceEntryPoint === '@astrojs/image/squoosh') { if (resolvedOptions.serviceEntryPoint === '@astrojs/image/squoosh') {
await copyWasmFiles(new URL('./chunks/', _buildConfig.server)); await copyWasmFiles(new URL('./assets/chunks/', _buildConfig.server));
} }
}, },
}, },

View file

@ -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. // Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
try { try {
const chunkFileNames = 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 chunkPath = npath.dirname(chunkFileNames);
const chunksDirUrl = new URL(chunkPath + '/', server); const chunksDirUrl = new URL(chunkPath + '/', server);
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true }); await fs.promises.rm(chunksDirUrl, { recursive: true, force: true });