-
Notifications
You must be signed in to change notification settings - Fork 5
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
add vite preset #14
add vite preset #14
Conversation
@wingleung are you still planning to actively maintain this project, or are you using something else nowadays? I'm planning to upgrade to Remix + Vite soon, and I'd love to see this get merged, and to see #44 get fixed. (I have a patch, but I haven't made a PR because the project seems stalled.) |
@brettdh apologies for the lack of activity on my part, it's been a busy. We're still using remix v2 with vite and our internal PR is still open to test the vite plugin 😞 I'll make sure to make to some time to test the vite plugin and be more active in this project the coming days 🙏 keep you posted! |
Really looking forward to this one! Can I help somehow? |
} | ||
) | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a section on local testing. What script targets would be appropriate to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meza good idea!
I usually test this with sam cli so I can reproduce the same infrastructure as I would use in AWS.
I created a simple remix example project where I added some readme, predefined npm scripts and already configured the vite preset for testing. Please check the readme if you want to give it a spin.
👉 https://github.com/wingleung/remix-aws-example
👉 especially this commit where I added the remix-aws setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! Also is there a reason to stay with awsgateway v1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I added a commit to make api gw v2 the default everywhere 👉 e5fdefb
it was already the default in the vite preset and in the createRequestHandler and the vite preset
f29ecec
to
cff2fac
Compare
Update package.json
cff2fac
to
9fb147f
Compare
2d8f26c
to
2afcbbe
Compare
@brettdh @meza I published a beta version which I use internally during our testing period for this, feel free to have a look. |
Awesome! About to dive in. Will report back when I got somewhere, thanks! |
Thanks for the update and the beta! Does this release contain the fix for #44 or not yet? (Just checking before I remove my local patch.) |
Looking at this again today, I'm actually not sure if I should use a preset. In my custom export const handler = initSentry(
handleWarmup(
ignoreBadRequestErrors(
createRequestHandler({
build,
mode: process.env.NODE_ENV,
awsProxy: AWSProxy.APIGatewayV2,
}) as AsyncHandler<APIGatewayProxyHandler>,
) as AsyncHandler<APIGatewayProxyHandler>,
) as AsyncHandler<APIGatewayProxyHandler>,
)
|
Ope I should read more carefully:
Will try this. |
One issue: it looks like my overriding of
|
Btw I've managed to make it all work with CDK. I'll distill it down and update the Trance Stack (which is well overdue) to all of what I've learned |
@brettdh hmm I should pass the I'll work on that, for now you could provide your own
|
@brettdh I think you added the I'll try to make a beta release tomorrow morning with the latest commits of this PR and of #44 🙏 export default defineConfig({
plugins: [
remix({
serverBuildFile: 'index.mjs',
presets: [
awsPreset(
{
awsProxy: AWSProxy.APIGatewayV1,
}
) as Preset
],
}), |
I also had it there but looking at the PR diff, it seemed like I also had to pass it as part of the preset config; otherwise it would use the default path of |
@brettdh I think I need to work on better documentation or self explanatory code 😅 the config for the preset itself only takes 2 config properties at the root
in the |
Ah, okay; thanks for the explanation. This was the crucial bit I was misunderstanding (emphasis mine):
I was misreading some sequence of calls and thinking that the ...aaaaalso it seems I was passing the result of Moving everything to the right spot and adding |
Not quite sure if this is related to remix-aws or not, but I now have this issue:
The referenced line is the last one in this block:
My `vite.config.ts` fileimport { vitePlugin as remix, VitePluginConfig } from "@remix-run/dev"
import { installGlobals } from "@remix-run/node"
import { awsPreset } from "remix-aws"
import { remixDevTools } from "remix-development-tools"
import { defineConfig } from "vite"
import type { UserConfig } from "vite"
import tsconfigPaths from "vite-tsconfig-paths"
import { getStaticAssetsBaseUrl } from "./utils.js"
installGlobals()
const isProd = process.env.NODE_ENV === "production"
const remixProdConfig: Partial<
Pick<VitePluginConfig, "serverBuildFile" | "presets">
> = isProd
? {
serverBuildFile: "index.mjs",
presets: [
awsPreset({
build: {
entryPoints: ["server.ts"],
outfile: "build/server/index.mjs",
},
}),
],
}
: {}
const viteProdConfig: Partial<Pick<UserConfig, "base" | "ssr">> = isProd
? {
base: `${getStaticAssetsBaseUrl()}/static/build`,
ssr: {
noExternal: true,
},
}
: {}
export default defineConfig({
build: {
sourcemap: true,
commonjsOptions: {
transformMixedEsModules: true, // I tried this based on a google search result but it didn't help
},
},
...viteProdConfig,
server: {
port: 3000,
},
plugins: [
remixDevTools(),
remix({
ignoredRouteFiles: ["**/.*", "**/*.css", "**/*.test.{js,jsx,ts,tsx}"],
...remixProdConfig,
}),
tsconfigPaths(),
],
}) My `server.ts` fileimport { installGlobals } from "@remix-run/node"
import * as Sentry from "@sentry/node"
import type { APIGatewayProxyHandler } from "aws-lambda"
import type { AsyncHandler } from "aws-lambda-consumer"
import { AWSProxy, createRequestHandler } from "remix-aws"
import sourceMapSupport from "source-map-support"
import { initSentry } from "~/lib/sentry.server"
// eslint-disable-next-line @typescript-eslint/no-var-requires
const build = require("./build/server/index")
if (process.env.NODE_ENV !== "production") {
require("./mocks")
}
installGlobals()
sourceMapSupport.install()
function handleWarmup(handler: AsyncHandler<APIGatewayProxyHandler>) {
// <snip>
}
/**
* Prevent Sentry trace reporting for all client-side errors in the UI.
*
* These are most commonly the result of scanner traffic, but even for
* invalid requests that occur during development, we don't particularly
* care about recording traces.
*/
function ignoreBadRequestErrors(handler: AsyncHandler<APIGatewayProxyHandler>) {
// <snip>
}
export const handler = initSentry(
handleWarmup(
ignoreBadRequestErrors(
createRequestHandler({
build,
mode: process.env.NODE_ENV,
awsProxy: AWSProxy.APIGatewayV2,
}) as AsyncHandler<APIGatewayProxyHandler>,
) as AsyncHandler<APIGatewayProxyHandler>,
) as AsyncHandler<APIGatewayProxyHandler>,
) |
Figured it out; I needed to add these lines to the preset's esbuild config:
|
Anything special I need to do to make this work with the vite |
Nevermind; there's something unexpected (to me) going on here where my Update: figured this out by passing a function to |
@wingleung something about the preset is messing up my server source maps. I'm using a variant of this script to check the source mapping of a particular line in my bundle, and when I remove the |
Happily, all the other testing I've done is working now 🥳 just the issue with the server bundle source maps remains. |
@brettdh first of all, thank you so much for taking the time to test this beta version 🙏 much appreciated!
☝️ the esbuild that is triggered by remix-aws should be more intelligent here and map the remix' vite config to esbuild, pushed a commit to map some more build configs to esbuild 👉 a05e6db
☝️ this is another example why remix-aws should be more intelligent by mapping the current build config to esbuild in the I mapped the
docs: https://remix.run/docs/en/main/guides/vite#new-build-output-paths
☝️ it might be possible 📢 I published a new beta version with the added mappings for you to test it on your setup 👉 1.2.0-beta.3 feel free to add more feedback here, I merged the PR so I could have a clean branching strategy to add multiple PRs into beta's of an upcoming version |
Installed 1.2.0-beta.3 and the server sourcemaps work perfectly. Thank you!! |
I added a few comments on a05e6db but they're pretty minor. Is there more testing or PR merging you want to do before releasing 1.2.0, or do you think that might happen pretty soon? |
closes #8
Added a Vite preset that will
server.js
which uses thecreateRequestHandler
fromremix-aws
You can provide your own
server.js
by providing your ownbuild.entryPoints
.You can provide your own
build.outfille
if you don't want to overwrite the remix server build.Check the readme for configuration details