-
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6048592
commit e447b9e
Showing
3 changed files
with
92 additions
and
65 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,78 @@ | ||
import {UserConfig, defineConfig} from "vite"; | ||
import {nodePolyfills} from "vite-plugin-node-polyfills"; | ||
import {visualizer} from "rollup-plugin-visualizer"; | ||
import topLevelAwait from "vite-plugin-top-level-await"; | ||
import {blsBrowserPlugin} from "./scripts/vite/plugins/blsBrowserPlugin.js"; | ||
|
||
export function getBaseViteConfig( | ||
pkgInfo: { | ||
description: string; | ||
version: string; | ||
author: string; | ||
license: string; | ||
homepage: string; | ||
}, | ||
{entry, libName}: {entry: string; libName: string} | ||
): UserConfig { | ||
// TODO: Investigate why this banner is not appended to the build header. | ||
const banner = | ||
`/* ${pkgInfo.description}\n` + | ||
" * \n" + | ||
` * Version: ${pkgInfo.version}\n` + | ||
` * Author: ${pkgInfo.author}\n` + | ||
` * License: ${pkgInfo.license}\n` + | ||
` * Web: ${pkgInfo.homepage}\n` + | ||
"*/"; | ||
|
||
return defineConfig({ | ||
plugins: [ | ||
topLevelAwait(), | ||
blsBrowserPlugin(), | ||
nodePolyfills({ | ||
include: ["http", "https", "stream"], | ||
globals: {Buffer: true, process: true}, | ||
protocolImports: true, | ||
}), | ||
...(process.env.CI ? [] : [visualizer()]), | ||
], | ||
mode: "production", | ||
appType: "custom", | ||
esbuild: { | ||
banner, | ||
legalComments: "none", | ||
}, | ||
build: { | ||
// "modules" refer to ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14'] | ||
target: "modules", | ||
outDir: "dist", | ||
sourcemap: true, | ||
minify: false, | ||
manifest: "manifest.json", | ||
ssr: false, | ||
ssrManifest: false, | ||
emptyOutDir: true, | ||
lib: { | ||
entry, | ||
formats: ["es"], | ||
name: libName, | ||
fileName: (format) => { | ||
if (format === "esm" || format === "es") { | ||
return `${libName.toLowerCase()}.min.mjs`; | ||
} else if (format === "cjs") { | ||
return `${libName.toLowerCase()}.min.cjs`; | ||
} else { | ||
return `${libName.toLowerCase()}.min.${format}.js`; | ||
} | ||
}, | ||
}, | ||
rollupOptions: { | ||
output: { | ||
inlineDynamicImports: true, | ||
}, | ||
treeshake: { | ||
preset: "recommended", | ||
}, | ||
}, | ||
}, | ||
}); | ||
} |
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