Skip to content

Commit

Permalink
Project update. [p][robotic]
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswrks committed Mar 21, 2023
1 parent 04441f1 commit 7b5f6ab
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 132 deletions.
20 changes: 20 additions & 0 deletions dev/.files/vite/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ export default async ({ mode, command /*, ssrBuild */ }) => {
* @see https://rollupjs.org/guide/en/#big-list-of-options
* @see https://vitejs.dev/config/build-options.html#build-rollupoptions
*/
const rollupChunkCounters = new Map();
const rollupConfig = {
input: isCMA // Absolute paths.
? cmaEntries
Expand All @@ -293,6 +294,25 @@ export default async ({ mode, command /*, ssrBuild */ }) => {
noConflict: true, // Like `jQuery.noConflict()`.
compact: 'prod' === mode, // Minify auto-generated snippets.

// By default, in library mode, Vite ignores `build.assetsDir`.
// This prevents that by enforcing a consistent location for chunks and assets.
chunkFileNames: (chunk) => {
// This function doesn’t have access to the current output format, unfortunately.
// However, we are setting `build.lib.formats` explicitly in the configuration below.
// Therefore, we know `es` comes first, followed by either `cjs` or `umd` output chunks.
// So, chunk counters make it possible to infer build output format, based on sequence.

const chunkKey = JSON.stringify(chunk); // JSON serialization.
const chunkCounter = Number(rollupChunkCounters.get(chunkKey) || 0) + 1;

const chunkFormat = chunkCounter > 1 ? 'cjs|umd' : 'es';
const chunkExt = 'cjs|umd' === chunkFormat ? 'cjs' : 'js';

rollupChunkCounters.set(chunkKey, chunkCounter); // Updates counter.
return path.join(path.relative(distDir, a16sDir), '[name]-[hash].' + chunkExt);
},
assetFileNames: (/* asset */) => path.join(path.relative(distDir, a16sDir), '[name]-[hash].[ext]'),

// Preserves module structure in CMAs built explicitly as dependencies.
// The expectation is that peers will build w/ this flag set as false, which is
// recommended, because preserving module structure in a final build has performance costs.
Expand Down
Loading

0 comments on commit 7b5f6ab

Please sign in to comment.