esbuild#Format TypeScript Examples

The following examples show how to use esbuild#Format. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From tsm with MIT License 7 votes vote down vote up
exports.$defaults = function (format: Format): Defaults {
	let { FORCE_COLOR, NO_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;

	let argv = process.argv.slice(2);

	let flags = new Set(argv);
	let isQuiet = flags.has('-q') || flags.has('--quiet');

	// @see lukeed/kleur
	let enabled = !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
		FORCE_COLOR != null && FORCE_COLOR !== '0' || process.stdout.isTTY
	);

	let idx = flags.has('--tsmconfig') ? argv.indexOf('--tsmconfig') : -1;
	let file = resolve('.', !!~idx && argv[++idx] || 'tsm.js');

	return {
		file: existsSync(file) && file,
		isESM: format === 'esm',
		options: {
			format: format,
			charset: 'utf8',
			sourcemap: 'inline',
			target: 'node' + process.versions.node,
			logLevel: isQuiet ? 'silent' : 'warning',
			color: enabled,
		}
	};
};
Example #2
Source File: utils.d.ts    From tsm with MIT License 6 votes vote down vote up
export function $defaults(format: Format): Defaults;
Example #3
Source File: esbuild.ts    From magic-js with MIT License 6 votes vote down vote up
/**
 * Resolves the entrypoint file for ESBuild,
 * based on the format and target platform.
 */
async function getEntrypoint(format?: Format, isRN?: boolean) {
  const findEntrypoint = async (indexTarget?: string) => {
    if (format && (await existsAsync(path.resolve(process.cwd(), `./src/index.${indexTarget}.ts`)))) {
      return `src/index.${indexTarget}.ts`;
    }

    return 'src/index.ts';
  };

  if (isRN) {
    return findEntrypoint('native');
  }

  switch (format) {
    case 'iife':
      return findEntrypoint('cdn');

    case 'esm':
      return findEntrypoint('es');

    case 'cjs':
    default:
      return findEntrypoint(format);
  }
}
Example #4
Source File: build.ts    From esbuild-plugin-less with Do What The F*ck You Want To Public License 5 votes vote down vote up
formats: Format[] = ['cjs', 'esm']
Example #5
Source File: build.ts    From esbuild-plugin-less with Do What The F*ck You Want To Public License 5 votes vote down vote up
getOutputFilename = (format: Format) => {
  switch (format) {
    case 'esm':
      return `${format}.mjs`;
    default:
      return `${format}.js`;
  }
}