Skip to content

Instantly share code, notes, and snippets.

@Lovor01
Created February 2, 2025 11:18
Show Gist options
  • Save Lovor01/07921a701c7de5e4ab6f471b0e8a865f to your computer and use it in GitHub Desktop.
Save Lovor01/07921a701c7de5e4ab6f471b0e8a865f to your computer and use it in GitHub Desktop.
Wordpress scripts HMR config for one or more blocks
// change webpack default config
const defaultConfig = require( '@wordpress/scripts/config/webpack.config.js' );
// eslint-disable-next-line import/no-extraneous-dependencies
require( 'dotenv' ).config();
/* Either define host, cert_location and key_location in .env file
i root directory of the project or encode strings here to use
https and hot reload under https. Alternatively, remove this config file
*/
function changeConfig ( config ) {
config.devServer = {
...config.devServer,
host: process.env.host,
server: {
type: 'https',
options: {
cert: process.env.cert_location,
key: process.env.key_location,
},
},
allowedHosts: [
process.env.host,
'localhost',
'127.0.0.1',
],
};
// enable this if you are not using weback 4 API-s
// config.experiments = { ...config.experiments, backCompat: false };
}
if ( process.env.NODE_ENV !== 'production' ) {
if (Array.isArray(defaultConfig)) {
for (const config of defaultConfig )
changeConfig( config );
} else {
changeConfig( defaultConfig );
}
}
module.exports = defaultConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment