webpack-uniter-plugin
v0.0.1
Published
Webpack-Uniter-Plugin - Webpack plugin for requiring PHP files from JavaScript with Uniter
Downloads
7
Readme
webpack-uniter-plugin
Webpack plugin for requiring PHP files from JavaScript using Uniter via uniter-loader.
Usage
npm install --save-dev webpack webpack-uniter-pluginSimple usage (requiring a single PHP module)
Add to webpack.config.js:
const UniterPlugin = require('webpack-uniter-plugin');
module.exports = {
context: __dirname,
entry: './js/src/index',
output: {
path: __dirname + '/dist/',
filename: 'browser.js'
},
plugins: [
new UniterPlugin()
]
};Define an empty uniter.config.js:
module.exports = {};Create a PHP module php/src/MyApp/doubleIt.php:
<?php
namespace MyApp;
$doubleIt = function ($num) {
return $num * 2;
};
return $doubleIt;Call from JS module js/src/index.js:
var doubleItModule = require('./php/src/MyApp/doubleIt.php')();
doubleItModule.execute().then(function (doubleIt) {
console.log('Double 4 is ' + doubleIt(4));
});Run Webpack:
mkdir dist
node_modules/.bin/webpack --devtool=source-map --mode=development --progressLoad the bundle on a webpage, demo.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webpack-Uniter-Plugin demo</title>
</head>
<body>
<h1>Webpack-Uniter-Plugin demo</h1>
<script src="dist/browser.js"></script>
</body>
</html>and open demo.html in a browser.
