diff --git a/packages/mattermost-plugin/scripts/hmrServer.js b/packages/mattermost-plugin/scripts/hmrServer.js new file mode 100644 index 00000000000..4f5dedb1807 --- /dev/null +++ b/packages/mattermost-plugin/scripts/hmrServer.js @@ -0,0 +1,20 @@ +require('sucrase/register') +require('../../../scripts/webpack/utils/dotenv') +const path = require('path') +const webpack = require('webpack') +const WebpackDevServer = require('webpack-dev-server/lib/Server') +const waitForFileExists = require('../../../scripts/waitForFileExists').default + +const hmrServer = async () => { + const mattermostPluginConfig = require('../webpack.config') + const mattermostPluginCompiler = webpack(mattermostPluginConfig) + const mattermostServer = new WebpackDevServer({...mattermostPluginConfig.devServer}, mattermostPluginCompiler) + + const queryMapExists = await waitForFileExists(path.join(__dirname, '../../../queryMap.json'), 20000) + if (!queryMapExists) throw Error('QueryMap Not Available. Run `yarn relay:build`') + + await mattermostServer.start(3002, 'localhost') +} + +hmrServer() + diff --git a/pm2.dev.config.js b/pm2.dev.config.js index c16a8d91207..f6f37093fb5 100644 --- a/pm2.dev.config.js +++ b/pm2.dev.config.js @@ -98,8 +98,8 @@ module.exports = { }, { name: 'Mattermost Plugin Dev Server', - script: 'yarn workspace parabol-mattermost-plugin dev', - instances: 1 + script: './scripts/hmrServer.js', + cwd: 'packages/mattermost-plugin' } ].map((app) => ({ env_production: {