Skip to content

Commit

Permalink
Demo prospective esbuild text loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
72636c committed Oct 11, 2022
1 parent 5097cd5 commit d2c4b4d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ set -e

ts-node --transpile-only src/skuba build "${@}"

printf '\n' >> lib/index.d.ts
cat src/loaders.d.ts >> lib/index.d.ts

chmod +x 'lib/skuba.js'
7 changes: 7 additions & 0 deletions src/cli/build/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ export const esbuild = async (
entryPoints,
format: compilerOptions.module === ModuleKind.CommonJS ? 'cjs' : undefined,
outdir: compilerOptions.outDir,
loader: {
// TODO: should we use an external file loader instead?
// https://esbuild.github.io/content-types/#external-file
'.gql': 'text',
'.graphql': 'text',
'.sql': 'text',
},
logLevel: debug ? 'debug' : 'info',
logLimit: 0,
platform:
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export * as GitHub from './api/github';
export * as Jest from './api/jest';
export * as Net from './api/net';

// evanw/esbuild#2388
/**
* evanw/esbuild#2388
*/
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace WebAssembly {
Expand Down
19 changes: 19 additions & 0 deletions src/loaders.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// N.B. these interoperate with `esbuild` but not with plain `tsc`.

declare module '*.gql' {
const text: string;

export default text;
}

declare module '*.graphql' {
const text: string;

export default text;
}

declare module '*.sql' {
const text: string;

export default text;
}

0 comments on commit d2c4b4d

Please sign in to comment.