Skip to content

Commit 941ff8d

Browse files
attempt to fix icon path and other asset issues in dist build
1 parent 02cf03d commit 941ff8d

File tree

4 files changed

+137
-16
lines changed

4 files changed

+137
-16
lines changed

package-lock.json

Lines changed: 103 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
}
4646
},
4747
"peerDependencies": {
48-
"svelte": "^5.0.0",
49-
"@sveltejs/kit": "^2.0.0"
48+
"@sveltejs/kit": "^2.0.0",
49+
"svelte": "^5.0.0"
5050
},
5151
"devDependencies": {
5252
"@sveltejs/adapter-auto": "^3.3.0",
@@ -77,16 +77,17 @@
7777
"tsx": "^4.19.2",
7878
"typescript": "^5.0.0",
7979
"typescript-eslint": "^8.0.0",
80-
"vite": "^5.0.11"
80+
"vite": "^5.0.11",
81+
"vite-plugin-static-copy": "^2.3.1"
8182
},
8283
"dependencies": {
83-
"accessible-autocomplete": "^3.0.1",
8484
"@dwp/dwp-frontend": "^3.3.0",
8585
"@maptiler/sdk": "^3.0.1",
8686
"@ministryofjustice/frontend": "^4.0.1",
8787
"@moduk/frontend": "^2.0.23",
8888
"@monaco-editor/loader": "^1.4.0",
8989
"@types/dompurify": "^3.0.5",
90+
"accessible-autocomplete": "^3.0.1",
9091
"csv-parser": "^3.0.0",
9192
"d3": "^7.9.0",
9293
"dompurify": "^3.2.5",

scripts/generate-index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,33 @@ function findSvelteFiles(dir: string): string[] {
3636
const svelteFilesInComponents = findSvelteFiles(componentsDir);
3737

3838
const exportedNames = new Set<string>(); // Keep track of names already exported
39+
const skippedFiles: string[] = []; // Track skipped files
3940

4041
const exports = svelteFilesInComponents
4142
.map((filePath) => {
4243
const name = basename(filePath, ".svelte");
44+
const fullImportPath = join("components", filePath).replace(/\\/g, "/");
4345

4446
// Only export if the name hasn't been used yet
4547
if (!exportedNames.has(name)) {
4648
exportedNames.add(name); // Mark name as used
47-
const importPath = join("components", filePath).replace(/\\\\/g, "/");
48-
return `export { default as ${name} } from './${importPath}';`;
49+
return `export { default as ${name} } from './${fullImportPath}';`;
4950
}
51+
skippedFiles.push(fullImportPath); // Log skipped file path
5052
return null; // Skip duplicate
5153
})
5254
.filter((line): line is string => line !== null); // Remove null entries
5355

54-
// Write the file only if there are no duplicates
56+
// Write the file
5557
writeFileSync(
5658
indexFile,
5759
`// this file is auto-generated — do not edit by hand\nimport "$lib/components_base.css";\n\n${exports.join("\n")}\n`,
5860
);
5961

60-
console.log(
61-
`Generated ${indexFile} with ${exports.length} unique exports from ./components. Duplicates were ignored.`,
62-
);
62+
let logMessage = `Generated ${indexFile} with ${exports.length} unique exports from ./components.`;
63+
64+
if (skippedFiles.length > 0) {
65+
logMessage += `\nSkipped ${skippedFiles.length} duplicate file(s):\n - ${skippedFiles.join("\n - ")}`;
66+
}
67+
68+
console.log(logMessage);

vite.config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { sveltekit } from "@sveltejs/kit/vite";
22
import { defineConfig } from "vite";
3+
import { viteStaticCopy } from "vite-plugin-static-copy";
34

45
export default defineConfig({
56
plugins: [
@@ -13,6 +14,22 @@ export default defineConfig({
1314
return code;
1415
},
1516
},
17+
viteStaticCopy({
18+
targets: [
19+
{
20+
src: "static/assets/fonts",
21+
dest: "assets", // dist/assets/fonts
22+
},
23+
{
24+
src: "static/assets/images",
25+
dest: "assets",// dist/assets/images
26+
},
27+
{
28+
src: "static/assets/govuk_publishing_components",
29+
dest: "assets", // dist/assets/govuk_publishing_components
30+
},
31+
],
32+
}),
1633
],
1734
server: {
1835
fs: {

0 commit comments

Comments
 (0)