Skip to content

Commit

Permalink
chore: enable hot-reloading on dashboard JS watch
Browse files Browse the repository at this point in the history
  • Loading branch information
abaicus committed Nov 8, 2024
1 parent ab3707d commit c74b9f6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"scripts": {
"build:dashboard": "wp-scripts build assets/src/dashboard/index.js --output-path=assets/build/dashboard",
"dev:dashboard": "wp-scripts start assets/src/dashboard/index.js --output-path=assets/build/dashboard",
"dev:dashboard": "wp-scripts start assets/src/dashboard/index.js --output-path=assets/build/dashboard --hot --allowed-hosts all",
"build-dev:dashboard": "NODE_ENV=development wp-scripts build assets/src/dashboard/index.js --output-path=assets/build/dashboard",
"build:media": "wp-scripts build assets/src/media/*.js --output-path=assets/build/media",
"dev:media": "wp-scripts start assets/src/media/*.js --output-path=assets/build/media",
Expand Down
40 changes: 40 additions & 0 deletions wp-scripts.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// wp-scripts.config.js
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
...defaultConfig,
devServer: {
...defaultConfig.devServer,
allowedHosts: [ 'all', '.test' ],
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
},
host: '0.0.0.0',
port: 8887,
hot: true,
https: true,
client: {
webSocketURL: 'wss://localhost:8887/ws',
overlay: true
},
setupMiddlewares: ( middlewares, devServer ) => {
if ( ! devServer ) {
throw new Error( 'webpack-dev-server is not defined' );
}

// Add CORS headers to all responses
devServer.app.use( ( req, res, next ) => {
res.header( 'Access-Control-Allow-Origin', '*' );
next();
});

return middlewares;
}
},
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 300
}
};

0 comments on commit c74b9f6

Please sign in to comment.