Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including php-loader with all npm packages installed. Try it out:

var phpLoader = require("php-loader")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

php-loader v0.2.0

php loader module for webpack

php loader for webpack

This package will load any php content and use php to turn it into a html page.



npm install php-loader


var fileContent = require("php!./file.php");
// => run file.php with php and return it as some content (html for example)

It can also be used inside the webpack configuration file (webpack.js):

module.exports = {
  module: {
    loaders: [
        test: /\.php$/,
        loaders: [

Documentation: Using loaders


Here is a list of the available configuration options:

  • proxy: set the name of a proxy script to be used as a loader for the resource
  • args: list of string to be added as arguments to the proxy (or php) script
  • dependancies: list of glob pattern of files on which the resource depend
  • debug: add depandancies as html comment in the output (this will modify the output of the php script, and can lead to invalid results)

example usage:

         loaders: [
          'php-loader?' + JSON.stringify({
            proxy: 'router.php',
            args: [ '--arg1=no' ],
            dependancies: [
              __dirname + '/www/api/v1.0/app/**/*.php',
              __dirname + '/www/templates/**/*.php'
            debug: true

In this case, the command to be executed by php-loader to get the file 'resource.php' will be:

  php router.php --arg1=no resource.php




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free