From 5a892e835a3edb63cb1f04d6f51c5d37894f3bb6 Mon Sep 17 00:00:00 2001 From: AirBorne04 <> Date: Sat, 11 Feb 2023 21:37:40 +0100 Subject: [PATCH 1/5] esbuild respects `vite.build.minify` option --- .changeset/many-eels-wait.md | 5 +++++ packages/integrations/cloudflare/src/index.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/many-eels-wait.md diff --git a/.changeset/many-eels-wait.md b/.changeset/many-eels-wait.md new file mode 100644 index 000000000000..8385894fcefc --- /dev/null +++ b/.changeset/many-eels-wait.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +add option to compile unminified code diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 7ba1cc63148a..0a04094fe280 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -1,4 +1,5 @@ import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; +import { ViteUserConfig } from 'astro'; import esbuild from 'esbuild'; import * as fs from 'fs'; import * as os from 'os'; @@ -39,6 +40,7 @@ const SERVER_BUILD_FOLDER = '/$server_build/'; export default function createIntegration(args?: Options): AstroIntegration { let _config: AstroConfig; let _buildConfig: BuildConfig; + let _viteConfig: ViteUserConfig; const isModeDirectory = args?.mode === 'directory'; return { @@ -71,6 +73,7 @@ export default function createIntegration(args?: Options): AstroIntegration { } }, 'astro:build:setup': ({ vite, target }) => { + _viteConfig = vite; if (target === 'server') { vite.resolve = vite.resolve || {}; vite.resolve.alias = vite.resolve.alias || {}; @@ -103,7 +106,7 @@ export default function createIntegration(args?: Options): AstroIntegration { allowOverwrite: true, format: 'esm', bundle: true, - minify: true, + minify: !!_viteConfig.build?.minify, banner: { js: SHIM, }, From 72bca22583c23cf12fe50e59b45e1e8b0bfe6cfb Mon Sep 17 00:00:00 2001 From: AirBorne04 <> Date: Sat, 11 Feb 2023 22:13:29 +0100 Subject: [PATCH 2/5] fixed settings read --- packages/integrations/cloudflare/src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 0a04094fe280..8c4f63212fdc 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -40,7 +40,6 @@ const SERVER_BUILD_FOLDER = '/$server_build/'; export default function createIntegration(args?: Options): AstroIntegration { let _config: AstroConfig; let _buildConfig: BuildConfig; - let _viteConfig: ViteUserConfig; const isModeDirectory = args?.mode === 'directory'; return { @@ -73,7 +72,6 @@ export default function createIntegration(args?: Options): AstroIntegration { } }, 'astro:build:setup': ({ vite, target }) => { - _viteConfig = vite; if (target === 'server') { vite.resolve = vite.resolve || {}; vite.resolve.alias = vite.resolve.alias || {}; @@ -98,7 +96,7 @@ export default function createIntegration(args?: Options): AstroIntegration { // A URL for the final build path after renaming const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, '.js')); - await esbuild.build({ + await esbuild.build({ target: 'es2020', platform: 'browser', entryPoints: [entryPath], @@ -106,7 +104,7 @@ export default function createIntegration(args?: Options): AstroIntegration { allowOverwrite: true, format: 'esm', bundle: true, - minify: !!_viteConfig.build?.minify, + minify: _config.vite?.build?.minify !== false, banner: { js: SHIM, }, From ad052323e89448f21d263aa2bce2e0b9ebb1d73c Mon Sep 17 00:00:00 2001 From: AirBorne04 <> Date: Sat, 11 Feb 2023 22:15:08 +0100 Subject: [PATCH 3/5] remove stale import --- packages/integrations/cloudflare/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 8c4f63212fdc..9e0ed2dcb843 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -1,5 +1,4 @@ import type { AstroAdapter, AstroConfig, AstroIntegration } from 'astro'; -import { ViteUserConfig } from 'astro'; import esbuild from 'esbuild'; import * as fs from 'fs'; import * as os from 'os'; From c420778268dab3cc20253f6dc144ae2fa31f7578 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 18 Apr 2023 16:01:57 +0200 Subject: [PATCH 4/5] Adding description for debug build --- packages/integrations/cloudflare/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 207952185097..245755c90f38 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -108,10 +108,29 @@ By default, `@astrojs/cloudflare` will generate a `_routes.json` file that lists ## Troubleshooting +If you run into issues + For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help! You can also check our [Astro Integration Documentation][astro-integration] for more on integrations. +Meaningful error messages + +Currently errors during running your application in wrangler are not very useful, due to minification of your code. For better debugging you can add `vite.build.minify = false` setting to your `astro.config.js` + +``` +export default defineConfig({ + adapter: cloudflare(), + output: 'server', + + vite: { + build: { + minify: false + } + } +}); +``` + ## Contributing This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! From 74a86c2467841dcaed65da521d57f6f128c91908 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 20 Apr 2023 14:49:00 +0200 Subject: [PATCH 5/5] Docs update Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com> --- packages/integrations/cloudflare/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/integrations/cloudflare/README.md b/packages/integrations/cloudflare/README.md index 245755c90f38..2e61063dbde6 100644 --- a/packages/integrations/cloudflare/README.md +++ b/packages/integrations/cloudflare/README.md @@ -108,15 +108,14 @@ By default, `@astrojs/cloudflare` will generate a `_routes.json` file that lists ## Troubleshooting -If you run into issues For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help! You can also check our [Astro Integration Documentation][astro-integration] for more on integrations. -Meaningful error messages +### Meaningful error messages -Currently errors during running your application in wrangler are not very useful, due to minification of your code. For better debugging you can add `vite.build.minify = false` setting to your `astro.config.js` +Currently, errors during running your application in Wrangler are not very useful, due to the minification of your code. For better debugging, you can add `vite.build.minify = false` setting to your `astro.config.js` ``` export default defineConfig({