From 31c02b8100cb45b889ca98dd2d75f1657a438e6a Mon Sep 17 00:00:00 2001 From: Thibaut Gauvin Date: Mon, 24 Jun 2024 12:02:37 +0200 Subject: [PATCH] feat(dev): use vite plugin static-copy to copy report data in build folder Can now use "vite dev" with HMR, instead of building app every time during developments. --- client/package-lock.json | 72 +++++++++++++++++++++++++++++++++++++++- client/package.json | 6 ++-- client/vite.config.ts | 13 +++++++- 3 files changed, 86 insertions(+), 5 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 5c145a85..d5d4f113 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -12,6 +12,7 @@ "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@types/eslint": "^8.56.7", + "@types/node": "^20.14.8", "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", @@ -23,7 +24,8 @@ "tslib": "^2.4.1", "typescript": "^5.0.0", "typescript-eslint": "^8.0.0-alpha.20", - "vite": "^5.0.3" + "vite": "^5.0.3", + "vite-plugin-static-copy": "^1.0.5" } }, "node_modules/@ampproject/remapping": { @@ -941,6 +943,15 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/node": { + "version": "20.14.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.8.tgz", + "integrity": "sha512-DO+2/jZinXfROG7j7WKFn/3C6nFwxy2lLpgLjEXJz+0XKphZlTLJ14mo8Vfg8X5BWN6XjyESXq+LcYdT7tR3bA==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/@types/pug": { "version": "2.0.10", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.10.tgz", @@ -1919,6 +1930,20 @@ "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, + "node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2194,6 +2219,18 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -3267,6 +3304,21 @@ } } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, + "node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3337,6 +3389,24 @@ } } }, + "node_modules/vite-plugin-static-copy": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/vite-plugin-static-copy/-/vite-plugin-static-copy-1.0.5.tgz", + "integrity": "sha512-02k0Rox+buYdEOfeilKZSgs1gXfPf9RjVztZEIYZgVIxjsVZi6AXssjzdi+qW6zYt00d3bq+tpP2voVXN2fKLw==", + "dev": true, + "dependencies": { + "chokidar": "^3.5.3", + "fast-glob": "^3.2.11", + "fs-extra": "^11.1.0", + "picocolors": "^1.0.0" + }, + "engines": { + "node": "^18.0.0 || >=20.0.0" + }, + "peerDependencies": { + "vite": "^5.0.0" + } + }, "node_modules/vitefu": { "version": "0.2.5", "resolved": "https://registry.npmjs.org/vitefu/-/vitefu-0.2.5.tgz", diff --git a/client/package.json b/client/package.json index c8e9ae10..efadff3f 100644 --- a/client/package.json +++ b/client/package.json @@ -4,9 +4,7 @@ "private": true, "scripts": { "dev": "vite dev", - "cp:fixtures": "cp -r ./fixtures/report-data/dev/* ./build/", "build": "vite build", - "start": "npm run build && npm run cp:fixtures && npx serve -p 3000 build/", "lint": "prettier --check . && eslint .", "format": "prettier --write ." }, @@ -15,6 +13,7 @@ "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@types/eslint": "^8.56.7", + "@types/node": "^20.14.8", "eslint": "^9.0.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-svelte": "^2.36.0", @@ -26,7 +25,8 @@ "tslib": "^2.4.1", "typescript": "^5.0.0", "typescript-eslint": "^8.0.0-alpha.20", - "vite": "^5.0.3" + "vite": "^5.0.3", + "vite-plugin-static-copy": "^1.0.5" }, "type": "module" } diff --git a/client/vite.config.ts b/client/vite.config.ts index 6e6f7919..905cc34a 100644 --- a/client/vite.config.ts +++ b/client/vite.config.ts @@ -1,9 +1,20 @@ import { sveltekit } from '@sveltejs/kit/vite'; +import { viteStaticCopy } from 'vite-plugin-static-copy'; import { resolve } from 'path'; +// Copy report data fixtures only during development +const viteStaticCopyReportData = viteStaticCopy({ + targets: [ + { + src: resolve('./fixtures/report-data/dev/*'), + dest: './' + } + ] +}); + /** @type {import('vite').UserConfig} */ const config = { - plugins: [sveltekit()], + plugins: [sveltekit(), process.env.NODE_ENV !== 'production' ? viteStaticCopyReportData : null], resolve: { alias: { $models: resolve('src/models'),