Merge pull request #12115 from keymanapp/feat/web/utf8-charset-output

This commit is contained in:
Joshua Horton 2024-08-27 19:02:07 +07:00 committed by GitHub
commit 95bcf99e64
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 31 additions and 7 deletions

View file

@ -3,6 +3,7 @@ import esbuild from 'esbuild';
import { esmConfiguration, forES6, iifeConfiguration } from './configuration.mjs';
import { prepareTslibTreeshaking } from './tslibTreeshaking.mjs';
let CHARSET = 'ascii';
let FORMAT = 'iife';
let MINIFY = false;
@ -28,6 +29,8 @@ Parameters:
Options:
--help Shows this script's documentation
--charset=<charset> Sets the charset type for esbuild to emit. Defaults to 'ascii'
but may also be 'utf8'.
--format=<format> Sets the format type to use for the generated bundle. Should be
'iife' or 'esm'.
@ -49,15 +52,28 @@ if(process.argv.length > 2) {
case '--help':
doHelp();
break;
case '--format': // bc TS uses this exact flag. esbuild... uses sourcemap (in the JS config)
let input = process.argv[++i];
switch(input) {
case 'iife':
case 'esm':
FORMAT = input;
case '--charset':
let charsetOption = process.argv[++i];
switch(charsetOption) {
case 'ascii':
case 'utf8':
CHARSET = charsetOption;
break;
default:
console.error(`Invalid bundling format specified: ${input}. Must be 'iife' or 'esm'.`);
console.error(`Invalid bundling format specified: ${charsetOption}. Must be 'ascii' or 'utf8'.`);
doHelp(1);
break;
}
break;
case '--format': // bc TS uses this exact flag. esbuild... uses sourcemap (in the JS config)
let formatOption = process.argv[++i];
switch(formatOption) {
case 'iife':
case 'esm':
FORMAT = formatOption;
break;
default:
console.error(`Invalid bundling format specified: ${formatOption}. Must be 'iife' or 'esm'.`);
doHelp(1);
break;
}
@ -128,6 +144,7 @@ const baseConfig = FORMAT == 'iife' ? iifeConfiguration : esmConfiguration;
const config: esbuild.BuildOptions = {
...jsVersionTarget == 'es6' ? forES6(baseConfig) : baseConfig,
entryPoints: [sourceFile],
charset: CHARSET as 'ascii' | 'utf8',
outfile: destFile,
minify: MINIFY,
metafile: !!profilePath,

View file

@ -55,11 +55,13 @@ compile_and_copy() {
$BUNDLE_CMD "${SRC_ROOT}/debug-main.js" \
--out "${BUILD_ROOT}/debug/keymanweb.js" \
--charset "utf8" \
--sourceRoot "@keymanapp/keyman/web/build/app/browser/debug" \
--target "es6"
$BUNDLE_CMD "${SRC_ROOT}/release-main.js" \
--out "${BUILD_ROOT}/release/keymanweb.js" \
--charset "utf8" \
--profile "${BUILD_ROOT}/filesize-profile.log" \
--sourceRoot "@keymanapp/keyman/web/build/app/browser/release" \
--minify \
@ -67,6 +69,7 @@ compile_and_copy() {
$BUNDLE_CMD "${BUILD_ROOT}/obj/test-index.js" \
--out "${BUILD_ROOT}/lib/index.mjs" \
--charset "utf8" \
--sourceRoot "@keymanapp/keyman/web/build/app/browser/lib" \
--format esm

View file

@ -45,11 +45,13 @@ compile_and_copy() {
$BUNDLE_CMD "${SRC_ROOT}/debug-main.js" \
--out "${BUILD_ROOT}/debug/keymanweb-webview.js" \
--charset "utf8" \
--sourceRoot "@keymanapp/keyman/web/build/app/webview/debug" \
--target "es6"
$BUNDLE_CMD "${SRC_ROOT}/release-main.js" \
--out "${BUILD_ROOT}/release/keymanweb-webview.js" \
--charset "utf8" \
--profile "${BUILD_ROOT}/filesize-profile.log" \
--sourceRoot "@keymanapp/keyman/web/build/app/webview/release" \
--minify \

View file

@ -64,6 +64,7 @@ function do_build() {
# The ES6 target needs no polyfills - we go straight to the wrapped version.
$bundle_cmd src/main/worker-main.ts \
--out $INTERMEDIATE/worker-main.js \
--charset "utf8" \
--target "es6" \
--sourceRoot '@keymanapp/keyman/web/src/engine/predictive-text/worker-thread/src/main'
@ -75,6 +76,7 @@ function do_build() {
$bundle_cmd src/main/worker-main.ts \
--out $INTERMEDIATE/worker-main.min.js \
--minify \
--charset "utf8" \
--profile build/filesize-profile.log \
--target "es6" \
--sourceRoot '@keymanapp/keyman/web/src/engine/predictive-text/worker-thread/src/main'