@iamota/iamota-webpack
Version:
Helper tools for Webpack for iamota Framework (WordPress and Shopify)
91 lines (79 loc) • 2.51 kB
JavaScript
// ----------------------------------------------------------------------------
// Webpack Dev Server Config
// ----------------------------------------------------------------------------
//
// Webpack Dev Server configuration
//
// ----------------------------------------------------------------------------
/**
* Load Dependencies
*/
const path = require('path');
/**
* Initialize Config
*/
let config = {};
exports.init = function(config) {
this.config = config;
return this;
};
/**
* Vagrant Dev Server
*/
exports.devServerVagrant = () => {
// Read the vagrant.json
const vagrantJSON = require(path.resolve(this.config.projectPath, 'vagrant.json'));
// Configure Ports
let vagrantPort = parseInt(vagrantJSON.http_port); // Read from JSON (e.g. 8095)
let devServerPort = vagrantPort + 1000; // Offset by 1000 (e.g. 9085)
// Debug Output
console.log('Vagrant: https://localhost:'+vagrantPort);
console.log('Webpack: https://localhost:'+devServerPort);
// Configure the Dev Server Configuration
return {
devServer: {
contentBasePublicPath: '/public',
compress: true,
historyApiFallback: true,
hot: this.config.hmr,
host: 'localhost',
port: devServerPort,
https: true,
index: '', // Enable root proxying
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
'**': {
target: 'https://localhost:'+vagrantPort,
secure: false,
changeOrigin: true,
pathRewrite: {
['localhost:'+vagrantPort] : 'localhost:'+devServerPort
},
}
}
},
output: {
publicPath: 'https://localhost:'+devServerPort+'/assets/'
}
};
};
/**
* Dev Server Config
*/
exports.devServer = ({
port = process.env.DEVSERVER_PORT
} = {}) => ({
devServer: {
compress: true,
historyApiFallback: true,
hot: true,
host: 'localhost',
port: port,
https: true
},
plugins: [
new this.config.webpack.HotModuleReplacementPlugin(),
],
});