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

perf: optimize client builds #643

Merged
merged 39 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7054987
wip: create get-client-build-details
aralroca Nov 18, 2024
9387f60
feat: first version of new WC compiler
aralroca Nov 21, 2024
98c1308
fix: fix some tests
aralroca Nov 22, 2024
fb9f877
feat: improve generate entrypoint code
aralroca Nov 24, 2024
0f6648f
refactor: refactor generateEntryPointCode module
aralroca Nov 24, 2024
69a6eb6
refactor: improve generate-entrypoint-code
aralroca Nov 24, 2024
7d90a1d
reformat: add comments
aralroca Nov 24, 2024
789edf5
feat: improve getTempPageName
aralroca Nov 24, 2024
561c549
refactor: move logic to preEntrypointAnalysis
aralroca Nov 24, 2024
e11172e
perf: convert analysis to concurrent
aralroca Nov 24, 2024
58e2303
test: cover pre-entrypoint-analysis tests
aralroca Nov 24, 2024
8e3bef6
feat: move file system temp entrypoint logic to module
aralroca Nov 24, 2024
4bcaa49
feat: improve pre-entrypoint-analysis
aralroca Nov 24, 2024
eb1092c
fix: solve layout
aralroca Nov 24, 2024
cc44a7a
test: fix test
aralroca Nov 24, 2024
0a9b0c8
test: fix tests
aralroca Nov 24, 2024
eef9107
fix: improve current get-client-code-in-page
aralroca Nov 24, 2024
a5f7dab
docs: modify plugins docs + fix type
aralroca Nov 24, 2024
4baf409
feat: add get-client-build-details
aralroca Nov 24, 2024
93acd90
feat: add runBuild helper
aralroca Nov 24, 2024
dd0d0cf
refactor: change param name
aralroca Nov 24, 2024
b4ca557
feat: integrate runBuild helper to get-client-code-in-page
aralroca Nov 25, 2024
aa55dca
test: cover runBuild
aralroca Nov 25, 2024
f2063a9
feat: add dependecy graph to client build
aralroca Nov 25, 2024
dbdb5c5
feat: integrate analysis
aralroca Nov 25, 2024
d64b17e
fix: change to concurrent code
aralroca Nov 25, 2024
87afa26
feat(build): adapt i18n key analysis to work in the new build
aralroca Nov 26, 2024
de27446
feat: adapt i18n bridge to new build
aralroca Nov 27, 2024
2526d9d
fix: return i18n size in build-time
aralroca Nov 28, 2024
c1618e7
reformat: rename getClientCodeInPage to layoutBuild
aralroca Nov 28, 2024
b5fa766
refactor: move clientPageBuild to module
aralroca Nov 28, 2024
288f727
refactor: move clientBuild
aralroca Nov 28, 2024
cb22c45
docs: remove comments
aralroca Nov 28, 2024
4659ca9
perf: optimize actions
aralroca Nov 28, 2024
68cd182
docs: clean comments
aralroca Nov 28, 2024
fd5fe09
feat(dx): improve build log feedback
aralroca Nov 28, 2024
a432fc9
feat(dx): improve build log feedback
aralroca Nov 28, 2024
8b6caae
feat(dx): fix log
aralroca Nov 28, 2024
496a19a
fix: fix integrations with plugins
aralroca Nov 30, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _brisa
**/out/*
**/out-*/*
**/dist/*
**/.temp-test-files/*
packages/brisa/index.js
packages/brisa/out
packages/brisa/jsx-runtime/
Expand Down
15 changes: 5 additions & 10 deletions docs/building-your-application/configuring/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { Configuration } from "brisa";
import { MyPlugin } from "my-plugin";

export default {
extendPlugins(plugins, { dev, isServer, entrypoint }) {
extendPlugins(plugins, { dev, isServer }) {
return [...plugins, MyPlugin];
},
} satisfies Configuration;
Expand All @@ -32,15 +32,10 @@ export default {

**Options:**

| Field | Type | Description |
| ---------- | --------------------- | ---------------------------------------------------- |
| dev | `boolean` | Indicates whether it's a development build. |
| isServer | `boolean` | Indicates whether it's a server build. |
| entrypoint | `string \| undefined` | Entry point for client builds, optional for servers. |

> [!NOTE]
>
> On the server it is only executed once and the build is with all the entrypoints, while on the client a separate build is made for each page, that's why on the client there is the `entrypoint` field in the options.
| Field | Type | Description |
| -------- | --------- | ------------------------------------------- |
| dev | `boolean` | Indicates whether it's a development build. |
| isServer | `boolean` | Indicates whether it's a server build. |

A plugin is defined as simple JavaScript object containing a name property and a setup function. Example of one:

Expand Down
5 changes: 2 additions & 3 deletions packages/brisa/src/cli/build-standalone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ async function compileStandaloneWebComponents(standaloneWC: string[]) {
let code = await Bun.file(path).text();

try {
const res = clientBuildPlugin(code, path, {
code = clientBuildPlugin(code, path, {
forceTranspilation: true,
customElementSelectorToDefine: webComponentsSelector[path],
});
code = res.code;
} catch (error) {
console.log(LOG_PREFIX.ERROR, `Error transforming ${path}`);
console.log(LOG_PREFIX.ERROR, (error as Error).message);
Expand All @@ -184,7 +183,7 @@ async function compileStandaloneWebComponents(standaloneWC: string[]) {
},
createContextPlugin(),
],
{ dev: !IS_PRODUCTION, isServer: false, entrypoint: '' },
{ dev: !IS_PRODUCTION, isServer: false },
),
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/brisa/src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getConstants } from '@/constants';
import byteSizeToString from '@/utils/byte-size-to-string';
import { logTable, generateStaticExport } from './build-utils';
import compileBrisaInternalsToDoBuildPortable from '@/utils/compile-serve-internals-into-build';
import { log } from '@/utils/log/log-build';

const outputText = {
bun: 'Bun.js Web Service App',
Expand All @@ -16,7 +17,6 @@ const outputText = {
};

export default async function build() {
const log = process.env.QUIET_MODE === 'true' ? () => {} : console.log;
const constants = getConstants();
const {
IS_PRODUCTION,
Expand Down
4 changes: 2 additions & 2 deletions packages/brisa/src/core/test/run-web-components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'node:path';
import fs from 'node:fs';
import { getConstants } from '@/constants';
import { transformToWebComponents } from '@/utils/get-client-code-in-page';
import { transformToWebComponents } from '@/utils/client-build/layout-build';
import getWebComponentsList from '@/utils/get-web-components-list';
import getImportableFilepath from '@/utils/get-importable-filepath';

Expand Down Expand Up @@ -29,7 +29,7 @@ export default async function runWebComponents() {
}

const res = await transformToWebComponents({
pagePath: '__tests__',
layoutPath: '__tests__',
webComponentsList: allWebComponents,
integrationsPath,
useContextProvider: true,
Expand Down
14 changes: 4 additions & 10 deletions packages/brisa/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,16 +866,10 @@ export type JSXComponent<
error?: JSXComponent<T & { error: unknown }>;
};

export type ExtendPluginOptions =
| {
dev: boolean;
isServer: true;
}
| {
dev: boolean;
isServer: false;
entrypoint: string;
};
export type ExtendPluginOptions = {
dev: boolean;
isServer: boolean;
};

export type ExtendPlugins = (
plugins: BunPlugin[],
Expand Down
15 changes: 11 additions & 4 deletions packages/brisa/src/utils/ast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { type ESTree, parseScript } from 'meriyah';
import { logError } from '../log/log-build';

export default function AST(loader: JavaScriptLoader = 'tsx') {
const transpiler =
typeof Bun !== 'undefined'
? new Bun.Transpiler({ loader })
: { transformSync: (code: string) => code };
const isBun = typeof Bun !== 'undefined';
const defaultTranspiler = { transformSync: (code: string) => code };

const minifier = isBun
? new Bun.Transpiler({ loader, minifyWhitespace: true })
: defaultTranspiler;

const transpiler = isBun ? new Bun.Transpiler({ loader }) : defaultTranspiler;

return {
parseCodeToAST(code: string): ESTree.Program {
Expand All @@ -28,5 +32,8 @@ export default function AST(loader: JavaScriptLoader = 'tsx') {
generateCodeFromAST(ast: ESTree.Program) {
return generate(ast, { indent: ' ' });
},
minify(code: string) {
return minifier.transformSync(code);
},
};
}
2 changes: 1 addition & 1 deletion packages/brisa/src/utils/brisa-error-dialog/inject-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function injectBrisaDialogErrorCode() {
// https://github.com/oven-sh/bun/issues/7611
await Bun.readableStreamToText(Bun.file(path).stream()),
internalComponentId,
).code,
),
loader,
}));
},
Expand Down
Loading
Loading