-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust build targets and fix typings
- ESM/MJS builds will target "full" ESM support with ES2020+ - CJS/UMD builds will target ES2019+ because this will transpile nullish coalescing and optional chaining operators, among other ES2020 features, which is syntax that older versions of Webpack, for example, may not support (just to increase compatibility a bit from ES2020) - Had to resort to non-bundled typings as the bundled typings that the TSC produces, it cannot consume for some strange reason Also added reference to canvas-txt PR that resulted in this new package in the README.
- Loading branch information
1 parent
706bfd9
commit 3c2de18
Showing
8 changed files
with
82 additions
and
20 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,11 @@ | ||
/** | ||
* Minimum targets for major browsers with native ES Modules, native ESM dynamic import, | ||
* and `import.meta` support. | ||
* @see https://vitejs.dev/config/build-options.html#build-target | ||
*/ | ||
export const esmBrowserTargets = [ | ||
'edge88', | ||
'firefox78', | ||
'chrome87', | ||
'safari14', | ||
]; |
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,47 @@ | ||
// | ||
// Browser library bundles | ||
// | ||
|
||
import path from 'node:path'; | ||
import url from 'node:url'; | ||
import { createRequire } from 'node:module'; | ||
import { defineConfig } from 'vite'; | ||
import { esmBrowserTargets } from './build-util.mjs'; | ||
|
||
const __dirname = path.basename(url.fileURLToPath(import.meta.url)); | ||
|
||
const require = createRequire(import.meta.url); | ||
const pkg: { name: string } = require( | ||
path.resolve(__dirname, '../package.json') | ||
) as { name: string }; | ||
const pkgName = pkg.name; | ||
|
||
export default defineConfig({ | ||
root: 'src', | ||
build: { | ||
// @see https://vitejs.dev/config/build-options.html#build-target | ||
// would be nice to make it es2020 but that means a lot of newer features | ||
// like dynamic imports, `import.meta`, nullish coalescing and optional | ||
// chaining operators, etc, that tend to not be supported in older bundlers | ||
target: ['es2019', ...esmBrowserTargets], | ||
outDir: '../dist', | ||
emptyOutDir: false, | ||
sourcemap: true, | ||
lib: { | ||
entry: 'lib/index.ts', | ||
name: 'textToCanvas', | ||
formats: ['cjs', 'umd'], | ||
fileName: (format) => { | ||
switch (format) { | ||
case 'umd': | ||
return `${pkgName}.umd.min.js`; | ||
case 'cjs': | ||
case 'commonjs': | ||
return `${pkgName}.min.js`; | ||
default: | ||
throw new Error(`Unknown build format "${format}"`); | ||
} | ||
}, | ||
}, | ||
}, | ||
}); |
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
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
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