Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/posandu/phpbuild
Make PHP assets fast
https://github.com/posandu/phpbuild
Last synced: 11 days ago
JSON representation
Make PHP assets fast
- Host: GitHub
- URL: https://github.com/posandu/phpbuild
- Owner: Posandu
- Created: 2022-04-26T13:22:34.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-01T06:03:02.000Z (over 2 years ago)
- Last Synced: 2025-01-13T01:18:28.963Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 349 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHPbuild
Make PHP apps faster!## Getting Started
First, you need to install node.js and npm. Then install pnpm.```bash
$ npm install -g pnpm
```Now, create a new directory and navigate to it.
```bash
$ mkdir my-app
$ cd my-app
```Clone the repository.
```bash
$ git clone https://github.com/Posandu/phpbuild.git .
```Install the dependencies.
```bash
$ pnpm install
```Now open 2 terminals and navigate to:
```
my-app/
my-app/dist/
```In the first terminal, run:
```bash
pnpm run dev
```In the second terminal, run the following command to start the php server:
```bash
php -S 0.0.0.0:8624
```Now open [http://localhost:8624/](http://localhost:8624/) in your browser. You should see the following:
![image](https://user-images.githubusercontent.com/76736580/166134295-0603855b-d265-4582-b6bf-303173fb8d64.png)
If you see the following, you have successfully installed PHPbuild. Now try editing the `index.php` file and see what happens. The page should be reloaded automatically.
## Commands
### `pnpm run dev`
Run the build process and hot reload process.### `pnpm run build`
Build the project. All the build files will be generated in the `build` directory.## PHP API
Now if you go to the `src/php` directory, you should see the following:```php
📦php
┣ 📜index.php // The main file
┗ 📜utils.php // The utils file (This is generated by PHPbuild)
``````php
require_once 'utils.php'; // We require the utils file//
js_file("index"); // include a javascript file (src/js/index.js)
scss_file("index"); // include a scss file (src/scss/index.scss)
hot_reload(); // Hot reload the page
```### `js_file($filename : string)`
Include a javascript file.
\$filename is the name of the file without the extension. It will be searched in the `src/js` directory. For example if we have a directory like this:```php
src/js/
┣ index.js
┣ _ignored.js
┣ index.notjs
```Then we can use `js_file("index")` to include the `index.js` file. All files starting with `_` will be ignored. And if we try to include a file that doesn't exist, we will get an error.
### `scss_file($filename : string)`
Include a scss file.
\$filename is the name of the file without the extension. It will be searched in the `src/scss` directory. For example if we have a directory like this:```php
src/scss/
┣ index.scss
┣ _ignored.scss
┣ index.notscss
```Then we can use `scss_file("index")` to include the `index.scss` file. All files starting with `_` will be ignored. And if we try to include a file that doesn't exist, we will get an error.
## Debugging
### `Hot reload failed. Please make sure you have a server running on port 5426.`
![image](https://user-images.githubusercontent.com/76736580/165697714-ca811172-67cd-4739-b246-3be21e739fc0.png)Make sure to run `pnpm run dev` in the project directory.
## Contributing
This project is open source and is hosted on Github. If you have any problems or suggestions, please open an issue or create a pull request.