Skip to content

Commit

Permalink
Merge pull request #2028 from hydephp/only-compile-app-scripts-if-it-…
Browse files Browse the repository at this point in the history
…has-content

[2.x] Only compile app scripts if it has contents
  • Loading branch information
caendesilva authored Nov 16, 2024
2 parents c42d8fe + 64b33c5 commit b418b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ This serves two purposes:
### Fixed

- Added missing collection key types in Hyde facade method annotations in https://github.com/hydephp/develop/pull/1784
- The `app.js` file will now only be compiled if it has scripts in https://github.com/hydephp/develop/pull/2028

### Security

Expand Down
9 changes: 8 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ const hydeVitePlugin = () => ({
}
});

const hasJavaScriptContent = () => {
const appJsPath = resolve(__dirname, 'resources/assets/app.js');
if (!fs.existsSync(appJsPath)) return false;
const content = fs.readFileSync(appJsPath, 'utf-8');
return content.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, '').trim().length > 0;
};

export default defineConfig({
server: {
port: 5173,
Expand All @@ -60,7 +67,7 @@ export default defineConfig({
emptyOutDir: false,
rollupOptions: {
input: [
resolve(__dirname, 'resources/assets/app.js'),
...(hasJavaScriptContent() ? [resolve(__dirname, 'resources/assets/app.js')] : []),
resolve(__dirname, 'resources/assets/app.css')
],
output: {
Expand Down

0 comments on commit b418b52

Please sign in to comment.