-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate ESZIP and JS bundles (#1)
* feat: create ESZIP bundle * refactor: use pathToFileURL * refactor: move ESZIP bundler to separate file * feat: add bundle identifier * feat: generate multiple bundles * refactor: remove variable
- Loading branch information
1 parent
97715d3
commit 8aff828
Showing
7 changed files
with
98 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { load } from 'https://deno.land/x/eszip@v0.16.0/loader.ts' | ||
import { build, LoadResponse } from 'https://deno.land/x/eszip@v0.16.0/mod.ts' | ||
|
||
const IDENTIFIER_BUNDLE_COMBINED = 'netlify:bundle-combined' | ||
|
||
const createLoader = (srcPath: string): ((specifier: string) => Promise<LoadResponse | undefined>) => { | ||
return async (specifier: string): Promise<LoadResponse | undefined> => { | ||
// If we're loading the combined bundle identifier, we override the loading | ||
// to read the file from disk and return the contents. | ||
if (specifier === IDENTIFIER_BUNDLE_COMBINED) { | ||
const content = await Deno.readTextFile(new URL(srcPath)) | ||
|
||
return { | ||
content, | ||
headers: { | ||
'content-type': 'application/typescript', | ||
}, | ||
kind: 'module', | ||
specifier, | ||
} | ||
} | ||
|
||
// Falling back to the default loading logic. | ||
return load(specifier) | ||
} | ||
} | ||
|
||
const [srcPath, destPath] = Deno.args | ||
const bytes = await build([IDENTIFIER_BUNDLE_COMBINED], createLoader(srcPath)) | ||
|
||
await Deno.writeFile(destPath, bytes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type BundleAlternate = 'js' | 'eszip2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { resolve } from 'path' | ||
|
||
const getESZIPBundler = () => { | ||
const { pathname } = new URL(import.meta.url) | ||
const bundlerPath = resolve(pathname, '../../deno/bundle.ts') | ||
|
||
return bundlerPath | ||
} | ||
|
||
export { getESZIPBundler } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters