Add CSS manifest aliases for SCSS entries
This commit is contained in:
+37
-1
@@ -1,8 +1,42 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { cpSync, mkdirSync } from 'node:fs';
|
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||||
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path';
|
||||||
import { collectEntries, normalizePath, shouldCopyFile, walkFiles } from './file-rules.js';
|
import { collectEntries, normalizePath, shouldCopyFile, walkFiles } from './file-rules.js';
|
||||||
|
|
||||||
|
const addScssManifestAliases = (outDir) => {
|
||||||
|
const manifestPath = join(outDir, 'manifest.json');
|
||||||
|
|
||||||
|
if (!existsSync(manifestPath)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
||||||
|
let changed = false;
|
||||||
|
|
||||||
|
for (const [key, entry] of Object.entries(manifest)) {
|
||||||
|
if (!key.endsWith('.scss')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cssKey = `${key.slice(0, -'.scss'.length)}.css`;
|
||||||
|
if (manifest[cssKey]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest[cssKey] = {
|
||||||
|
...entry,
|
||||||
|
src: cssKey,
|
||||||
|
name: cssKey,
|
||||||
|
names: Array.isArray(entry.names) ? Array.from(new Set([cssKey, ...entry.names])) : [cssKey]
|
||||||
|
};
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changed) {
|
||||||
|
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({
|
const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({
|
||||||
name: 'copy-bridgeable-server-files',
|
name: 'copy-bridgeable-server-files',
|
||||||
buildStart() {
|
buildStart() {
|
||||||
@@ -25,6 +59,8 @@ const copyServerFilesPlugin = ({ sourceDir, outDir }) => ({
|
|||||||
mkdirSync(dirname(destination), { recursive: true });
|
mkdirSync(dirname(destination), { recursive: true });
|
||||||
cpSync(absolutePath, destination);
|
cpSync(absolutePath, destination);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addScssManifestAliases(outDir);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user