Skip to content

Commit ff21c4a

Browse files
authored
Merge pull request #2011 from hydephp/no-longer-copy-assets-from-asset-bundler
No longer copy files to site output from the asset bundler command
2 parents a1b0783 + 0e81adb commit ff21c4a

4 files changed

Lines changed: 5 additions & 46 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ This serves two purposes:
9090
- We now use the much faster `CRC32` hashing algorithm instead of `MD5` for cache busting keys in https://github.com/hydephp/develop/pull/1918
9191
- **Replaced Laravel Mix with Vite for frontend asset compilation** in https://github.com/hydephp/develop/pull/2010
9292
- **Breaking:** You must now use `npm run build` to compile your assets, instead of `npm run prod`
93+
- 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
9394

9495

9596
### Deprecated

docs/creating-content/managing-assets.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ Then run `npm run dev` to compile the assets in development mode. For production
6262

6363
Hyde uses [Vite](https://vite.dev/) to compile assets.
6464

65-
When running the `npm run dev/prod` command, the following happens:
65+
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.
6666

67-
1. Vite will compile the `resources/assets/app.css` file into `_media/app.css` using PostCSS with TailwindCSS and AutoPrefixer.
68-
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`.
67+
The compiled assets will then be automatically copied to `_site/media` when you run `php hyde build`.
6968

7069
## Telling Hyde where to find assets
7170

monorepo/scripts/tests/project-styles.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
$output = shell_exec('cd '.BASE_PATH.' && npm run build');
2121

2222
$this->assert(file_exists(BASE_PATH.'/_media/app.css'), 'CSS file does not exist');
23-
$this->assert(file_exists(BASE_PATH.'/_site/media/app.css'), 'CSS file does not exist');
24-
2523
$this->assert(file_exists(BASE_PATH.'/_media/app.js'), 'JS file does not exist');
26-
$this->assert(file_exists(BASE_PATH.'/_site/media/app.js'), 'JS file does not exist');
2724
});

vite.config.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default defineConfig({
1717
}
1818
},
1919
build: {
20-
outDir: '_site/media',
20+
outDir: '_media',
2121
emptyOutDir: true,
2222
rollupOptions: {
2323
input: [
@@ -30,43 +30,5 @@ export default defineConfig({
3030
assetFileNames: '[name].[ext]'
3131
}
3232
}
33-
},
34-
plugins: [
35-
{
36-
name: 'copy-media',
37-
writeBundle() {
38-
// Copy files from _site/media to _media
39-
const fs = require('fs');
40-
const path = require('path');
41-
42-
const sourceDir = '_site/media';
43-
const targetDir = '_media';
44-
45-
if (!fs.existsSync(targetDir)) {
46-
fs.mkdirSync(targetDir, { recursive: true });
47-
}
48-
49-
// Copy all files recursively
50-
function copyRecursively(source, target) {
51-
const files = fs.readdirSync(source);
52-
53-
files.forEach(file => {
54-
const sourcePath = path.join(source, file);
55-
const targetPath = path.join(target, file);
56-
57-
if (fs.lstatSync(sourcePath).isDirectory()) {
58-
if (!fs.existsSync(targetPath)) {
59-
fs.mkdirSync(targetPath, { recursive: true });
60-
}
61-
copyRecursively(sourcePath, targetPath);
62-
} else {
63-
fs.copyFileSync(sourcePath, targetPath);
64-
}
65-
});
66-
}
67-
68-
copyRecursively(sourceDir, targetDir);
69-
}
70-
}
71-
]
33+
}
7234
});

0 commit comments

Comments
 (0)