-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Build/bundle assets and CSS #1786
Conversation
🦋 Changeset detectedLatest commit: a1c7c48 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
78277a1
to
d7a5898
Compare
🤔 btw when trying to build Is there a way I can get better introspection into what's going on? |
that's pretty weird 🤔 (https://github.com/snowpackjs/astro/runs/4169598680?check_suite_focus=true#step:7:236) |
@jasikpark looks like |
right, when testing on this branch + the changes in #1775 though, I still get: Maybe that's not an assets thing though 🤷♂️ |
01135ad
to
757ca1a
Compare
@jasikpark I just rebased with |
@@ -66,7 +66,7 @@ | |||
"@babel/traverse": "^7.15.4", | |||
"@proload/core": "^0.2.1", | |||
"@proload/plugin-tsm": "^0.1.0", | |||
"@web/rollup-plugin-html": "^1.10.1", |
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.
🎉
I still have the same problem... maybe it's somehow just a problem in Gitpod??? Want to enable the |
@@ -71,3 +71,7 @@ export function resolveDependency(dep: string, astroConfig: AstroConfig) { | |||
// For Windows compat, we need a fully resolved `file://` URL string | |||
return pathToFileURL(resolved).toString(); | |||
} | |||
|
|||
export function viteifyPath(pathname: string): string { |
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.
Ha I like the name
@@ -0,0 +1,10 @@ | |||
import type { ComponentPreload } from '../ssr/index'; | |||
import type { RouteData } from '../../@types/astro-core'; |
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.
What’s the reason for this type file living here and not @types
?
input, | ||
extractAssets: false, | ||
}) as any, // "any" needed for CI; also we don’t need typedefs for this anyway | ||
rollupPluginAstroBuildHTML({ |
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.
💯
const [renderers, mod] = await preload(ssrOpts); | ||
return render(renderers, mod, ssrOpts); | ||
} catch (e: unknown) { | ||
await errorHandler(e, ssrOpts.viteServer, ssrOpts.filePath); |
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.
Nice cleanup!
|
||
const ASTRO_PAGE_STYLE_PREFIX = '@astro-page-all-styles'; | ||
|
||
const isCSSRequest = (request: string) => STYLE_EXTENSIONS.has(path.extname(request)); |
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.
Vite may sometimes append query params to URLs, e.g. styles.css?direct
. Probably safest to make sure those are being handled as well.
@@ -48,6 +48,7 @@ export interface TopLevelAstro { | |||
|
|||
export interface SSRMetadata { | |||
renderers: Renderer[]; | |||
pathname: string; |
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.
Where is pathname
used? Can this be a URL or no?
allPages[route.component] = { | ||
route, | ||
paths: [route.pathname], | ||
preload: await ssrPreload({ |
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.
I like the preload approach. Clever
}); | ||
renderedPageMap.set(id, html); | ||
|
||
const document = parse5.parse(html, { |
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.
Just a sidenote: if we like parse5 better we should probably replace htmlparser2 with this (I didn’t profile parse5; I just went with htmlparser2 because it’s fast, easy-to-use, and actively maintained)
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.
Was going to be my comment as well. I'm fine with either, but we should only use one.
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.
Looking good! Drew covered all of my comments
if (!PREPROCESSOR_EXTENSIONS.has(lang)) { | ||
export async function transformWithVite({ value, attrs, transformHook, id, ssr, force }: TransformWithViteOptions): Promise<vite.TransformResult | null> { | ||
let lang = (`.${attrs.lang}` || '').toLowerCase(); // add leading "."; don’t be case-sensitive | ||
if (!force && !PREPROCESSOR_EXTENSIONS.has(lang)) { |
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.
note that this is not a needed change any more
Co-authored-by: Drew Powers <1369770+drwpow@users.noreply.github.com>
Not fully working, eg https://stackblitz.com/edit/github-d4rp6r?file=package.json - |
* Bundling CSS * Current progress of building assets * New build progress * Its finally working * Force css to go through the build * Prettier filenames * Split into separate CSS and HTML plugins * Always have at least one input * Bring back in sitemaps + output * Bring back srcset support * Bundle CSS * Bring back minify * Update dynamic tests * Update remaining tests * Linting * Fix remaining broken test * Use fs directly * Adding a changeset * Use path.posix * Debugging windows * More debugging * Pass URLs into readFile * Remove some debugging stuff * Remove force flag from transformWithVite * Update packages/astro/src/vite-plugin-build-css/index.ts Co-authored-by: Drew Powers <1369770+drwpow@users.noreply.github.com> Co-authored-by: Drew Powers <1369770+drwpow@users.noreply.github.com>
Changes
Testing
Docs
N/A