From 0e81adbe86e27f6c9cd641c1c1f6fce0dd8a5152 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 11 Nov 2024 13:55:27 +0100 Subject: [PATCH] No longer copy files to site output from NPM build command --- RELEASE_NOTES.md | 1 + docs/creating-content/managing-assets.md | 5 ++- monorepo/scripts/tests/project-styles.php | 3 -- vite.config.js | 42 ++--------------------- 4 files changed, 5 insertions(+), 46 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 74945acbaec..2ce391e580a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -90,6 +90,7 @@ This serves two purposes: - We now use the much faster `CRC32` hashing algorithm instead of `MD5` for cache busting keys in https://github.com/hydephp/develop/pull/1918 - **Replaced Laravel Mix with Vite for frontend asset compilation** in https://github.com/hydephp/develop/pull/2010 - **Breaking:** You must now use `npm run build` to compile your assets, instead of `npm run prod` + - Bundled assets are now compiled directly into the `_media` folder, and will not be copied to the `_site/media` folder by the NPM command in https://github.com/hydephp/develop/pull/2011 ### Deprecated diff --git a/docs/creating-content/managing-assets.md b/docs/creating-content/managing-assets.md index 332c9b7c2dd..e26479b09f2 100644 --- a/docs/creating-content/managing-assets.md +++ b/docs/creating-content/managing-assets.md @@ -62,10 +62,9 @@ Then run `npm run dev` to compile the assets in development mode. For production Hyde uses [Vite](https://vite.dev/) to compile assets. -When running the `npm run dev/prod` command, the following happens: +When running the `npm run dev/prod` command, Vite will compile the `resources/assets/app.css` file into `_media/app.css` using PostCSS with TailwindCSS and AutoPrefixer. -1. Vite will compile the `resources/assets/app.css` file into `_media/app.css` using PostCSS with TailwindCSS and AutoPrefixer. -2. Vite then copies the `_media` folder into `_site/media`, this is so that they are automatically accessible to your site without having to rerun `php hyde build`. +The compiled assets will then be automatically copied to `_site/media` when you run `php hyde build`. ## Telling Hyde where to find assets diff --git a/monorepo/scripts/tests/project-styles.php b/monorepo/scripts/tests/project-styles.php index 4ca8741482c..3054ff1fd6f 100644 --- a/monorepo/scripts/tests/project-styles.php +++ b/monorepo/scripts/tests/project-styles.php @@ -20,8 +20,5 @@ $output = shell_exec('cd '.BASE_PATH.' && npm run build'); $this->assert(file_exists(BASE_PATH.'/_media/app.css'), 'CSS file does not exist'); - $this->assert(file_exists(BASE_PATH.'/_site/media/app.css'), 'CSS file does not exist'); - $this->assert(file_exists(BASE_PATH.'/_media/app.js'), 'JS file does not exist'); - $this->assert(file_exists(BASE_PATH.'/_site/media/app.js'), 'JS file does not exist'); }); diff --git a/vite.config.js b/vite.config.js index d786c16d3d7..6d088d3819a 100644 --- a/vite.config.js +++ b/vite.config.js @@ -17,7 +17,7 @@ export default defineConfig({ } }, build: { - outDir: '_site/media', + outDir: '_media', emptyOutDir: true, rollupOptions: { input: [ @@ -30,43 +30,5 @@ export default defineConfig({ assetFileNames: '[name].[ext]' } } - }, - plugins: [ - { - name: 'copy-media', - writeBundle() { - // Copy files from _site/media to _media - const fs = require('fs'); - const path = require('path'); - - const sourceDir = '_site/media'; - const targetDir = '_media'; - - if (!fs.existsSync(targetDir)) { - fs.mkdirSync(targetDir, { recursive: true }); - } - - // Copy all files recursively - function copyRecursively(source, target) { - const files = fs.readdirSync(source); - - files.forEach(file => { - const sourcePath = path.join(source, file); - const targetPath = path.join(target, file); - - if (fs.lstatSync(sourcePath).isDirectory()) { - if (!fs.existsSync(targetPath)) { - fs.mkdirSync(targetPath, { recursive: true }); - } - copyRecursively(sourcePath, targetPath); - } else { - fs.copyFileSync(sourcePath, targetPath); - } - }); - } - - copyRecursively(sourceDir, targetDir); - } - } - ] + } }); \ No newline at end of file