Start Apache via webpack-dev-server.
npm install apache-webpack-pluginwebpack-dev-server.apache-webpack-plugin is a plugin for webpack-dev-server that starts your locally installed Apache web server when you run webpack-dev-server. This is not a replacement for Apache, so you must have Apache installed in order to use apache-webpack-plugin to connect.
apache-webpack-plugin is built with apache-bridge.
* Installation
* Usage
* Documentation
* apache.bin
* apache.conf
* apache.hostname
* apache.onCreateServer
* apache.port
Install and inject into package.json as a devDependency:
``bash`
npm install apache-webpack-plugin --save-dev
or install globally:
`bash`
npm install -g apache-webpack-plugin
webpack.config.js:
`javascript
// Require apache-webpack-plugin
var Apache = require('apache-webpack-plugin');
module.exports = {
// Set main js file
entry: './src/webpack/index.js',
// Set some output options
output: {
filename: 'bundle.js',
path: '/path/to/dist',
},
// ...
// Create instance of Apache plugin
plugins: [
new Apache({
hostname: 'localhost',
port: 8000
})
]
};
`
See webpack documentation for more information about configuration options.
If the path to your Apache httpd file is not inclued in your $PATH environment variable, you can specify the path explicitly via apache.bin:
`javascript`
new Apache({
bin: '/path/to/apache/bin',
hostname: 'localhost',
port: 8000
})
You can also manually add the path to process.env.PATH:
`javascript
process.env.PATH = '/path/to/apache/bin:' + process.env.PATH;
module.exports = {
// ...
}
`
Most webpack-dev-server implementations let webpack inject the bundle(s) into the page. Since we will be serving the page with Apache, we have to define a publicPath in the output block of our webpack.config.js and manually embed the any bundles in our HTML.
webpack.config.js:
`javascript`
output: {
filename: 'bundle.js',
path: '/path/to/dist',
publicPath: 'http://localhost:8080/js/'
}
index.php:
`php`
`bash`
$ node_modules/.bin/webpack-dev-server
See webpack-dev-server usage instructions on GitHub for more options for starting the server.
#### apache.bin
- Defaults to ''.
Set path to Apache bin directory where Apache httpd is located. This may be necessary if the path is not defined in your system's $PATH environment variable.
#### apache.conf
- | |
Boolean, string, or null value that indicates whether Apache should load its default httpd.conf file (true|null), another config file (string path to config file), or no config at all (false).
#### apache.hostname
-
The domain name or IP address for the server. Defaults to localhost.
#### apache.onCreateServer
- | server
- plugin
- Plugin instance. Note: This argument will be replaced by an instance of Apache Connect in v1.0.0 of apache-webpack-plugin.options
-
A function (or array of functions) to be called after the server object is created but before Apache starts, to allow integrating libraries that need access to the server configuration.
`javascript`
new Apache({
// ...
onCreateServer: function(server, plugin, options) {
server.on('configure', function(conf) {
conf.file = '/path/to/alternate/conf/file.conf';
conf.end();
});
}
})
See apache-bridge for more details about the apache_bridge.Server class.
#### apache.port
-
Port of remote server. Defaults to 80`.