Skip to content

Commit

Permalink
fix: Add treeshaking to the bundler, more tweaks; Output file in .fle…
Browse files Browse the repository at this point in the history
…ek folder; (#2)

## Why?

- Remove unnecessary code from the bundle.
- Less restrictive bundling.
- Target the browser for more Deno/v8 compatibility.
- Output file in the folder so we can more easily access the
bundled/uploaded code.

## How?

- Tweaked esbuild configuration
- mkdir over tmpdir

## Tickets?

-
[APP2-955](https://linear.app/fleekxyz/issue/APP2-955/investigate-user-issues-with-bundling)

## Contribution checklist?

- [x] The commit messages are detailed
- [x] The `build` command runs locally
- [x] Assets or static content are linked and stored in the project
- [x] You have manually tested
- [ ] You have provided tests

## Security checklist?

- [x] Sensitive data has been identified and is being protected properly
- [x] Injection has been prevented (parameterized queries, no eval or
system calls)

## Preview?

Optionally, provide the preview url here
  • Loading branch information
gabrielmpinto authored Jun 27, 2024
1 parent e407ec9 commit ffb4189
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/commands/functions/utils/getCodeFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { build, BuildOptions, Plugin } from 'esbuild';
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { filesFromPaths } from 'files-from-path';
import * as fs from 'fs';
import os from 'os';

import { output } from '../../../cli';
import { t } from '../../../utils/translation';
Expand Down Expand Up @@ -75,7 +74,12 @@ const bundleCode = async (args: BundleCodeArgs) => {
cliProgress.Presets.shades_grey
);

const tempDir = os.tmpdir();
const tempDir = '.fleek';

if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir);
}

const outFile = tempDir + '/function.js';
const unsupportedModulesUsed = new Set<string>();

Expand Down Expand Up @@ -115,8 +119,11 @@ const bundleCode = async (args: BundleCodeArgs) => {
entryPoints: [filePath],
bundle: true,
logLevel: 'silent',
platform: 'neutral',
mainFields: ['module', 'main'],
platform: 'browser',
format: 'esm',
target: 'esnext',
treeShaking: true,
mainFields: ['browser', 'module', 'main'],
external: [...Object.values(supportedModulesAliases)],
alias: supportedModulesAliases,
outfile: outFile,
Expand Down

0 comments on commit ffb4189

Please sign in to comment.