parcel-bundler / parcel

The zero configuration build tool for the web. πŸ“¦πŸš€
https://parceljs.org
MIT License
43.46k stars 2.27k forks source link

πŸ™‹ How about php files? #262

Closed Sigizmund2012 closed 6 years ago

Sigizmund2012 commented 6 years ago

Just now I have project on my local server with php files( form handlers ). If I run Parcel on watch mode, php files not copying to dist folder and browser is not reload if I change those files.

πŸ€” Expected Behavior

I want from Parcel to reload browser( and index.php too ), when I change php files and copy them to dist folder.

😯 Current Behavior

The files not copying to dist folder, and browser not reloading, when I change php files.

DeMoorJasper commented 6 years ago

Do you expect Parcel to just copy them over like they are html or really process and execute them as php?

Sigizmund2012 commented 6 years ago

Just copy like html and parse entry points of course :) I have my own local server, that executes php. But optional execution php may be the nice feature.

chee commented 6 years ago

this is just a matter of registering .php as an HTMLAsset, right? the user can then parcel watch index.php and then serve their dist with their php server

DeMoorJasper commented 6 years ago

It is if it’s about just html but if the point is decently supporting it than it’s bit more complex.

Sent with GitHawk

chee commented 6 years ago

absolutely, but what would decently supporting them be? a php dev server? that seems out of scope

DeMoorJasper commented 6 years ago

Seems more like a plugin to me, thats why i labeled it help wanted

chee commented 6 years ago

I don't think a plugin is even needed, I can't think of any special bundling that could be performed for php that wouldn't be already performed by HTMLAsset. correct me if i'm wrong.

The only thing is the php would not execute on the current parcel index.php.

They can use parcel watch index.php and serve their dist/ with any php-enabled server, however, and still get the benefits of parcel.

Provided php is a registered HTML extension

chee commented 6 years ago

Oh, of course, other referenced php files wouldn't be copied without special treatment. i'm a fool

DeMoorJasper commented 6 years ago

Feel free to test out your approach and do a PR @chee

devanflaherty commented 6 years ago

Hey there, I'm sure I'm not completely getting this, but in my mind I'm thinking Parcel could be great for a simple wordpress build. I read through this thinking it might shed some light but still lost.

I can't seem to wrap my head around on how to get it to work in wordpress build, am I wrong in my thinking that this parcel could be a good solution in this instance?

chee commented 6 years ago

i have built a plugin that works with very, very simple php programs (ones that only ever include/require files with relative string paths, or dirname(__FILE__) + string paths) to get an idea of what's involved. it works very well, but could not handle a real php application. for a full php application, like a wordpress app, it would need quite a bit more work of ast walk work, translating to dependencies the various ways of including a file in php.

@devanflaherty which part of a wordpress build would you hope to use it for? what job would parcel be doing?

i haven't used a bundler along with a wordpress application, and i'm not sure where it fits in.

ivanjuras commented 6 years ago

I'd also like to know if it's possible to use Parcel with WordPress.

My use case is simple: I just want to split my scripts.js file into multiple files and bundle them together into a script that gets called in a wp_enqueue_script function.

I hate the fact that I have to use Webpack for that.

chee commented 6 years ago

@ivanjuras of course! you can use your scripts.js as your entry, so break your scripts.js up and then do parcel build scripts.js

devongovett commented 6 years ago

Closing. If you want to add support for php somehow, feel free to write a plugin!

jcklpe commented 5 years ago

@ivanjuras I imagine this is way old to reply to you, but just to let you know, you can use gulp for what you want to do with wordpress and it's way easier than webpack for that limited level of bundling needed. I actually skipped gulp to learn webpack because it's supposed to be the future, and it does work, but gulp handles php stuff much easier. If you like, I'd recommend this article on the subject: https://www.sitepoint.com/fast-gulp-wordpress-theme-development-workflow/

hirasso commented 4 years ago

I wrote a plugin for that: https://www.npmjs.com/package/parcel-plugin-watch-reload

krystyna93 commented 1 year ago

I wrote a plugin for that: https://www.npmjs.com/package/parcel-plugin-watch-reload

Thanks for this plugin, I was worried I couldn't use PHP with Parcel, so thanks a bunch!