Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start plugin and app separately [LIBS-391] [LIBS-392] #848

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions cli/config/plugin.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
path: paths.shellBuildOutput,
filename: isProduction
? 'static/js/plugin-[name].[contenthash:8].js'
: 'static/js/plugin.bundle.js',
: 'static/js/plugin-[name].bundle.js',
chunkFilename: isProduction
? 'static/js/plugin-[name].[contenthash:8].chunk.js'
: 'static/js/plugin-[name].chunk.js',
Expand Down Expand Up @@ -192,9 +192,7 @@ module.exports = ({ env: webpackEnv, config, paths }) => {
// dhis2: Inject plugin static assets to the existing SW's precache
// manifest. Don't need to do in dev because precaching isn't done
// in dev environments.
// Check the actual NODE_ENV because `isProduction` is currently
// always true due to a bug (see src/lib/plugin/start.js)
process.env.NODE_ENV === 'production' &&
isProduction &&
new WorkboxWebpackPlugin.InjectManifest({
swSrc: paths.shellBuildServiceWorker,
injectionPoint: 'self.__WB_PLUGIN_MANIFEST',
Expand Down
39 changes: 23 additions & 16 deletions cli/src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const handler = async ({
shell: shellSource,
proxy,
proxyPort,
app: shouldStartOnlyApp,
plugin: shouldStartOnlyPlugin,
}) => {
const paths = makePaths(cwd)

Expand Down Expand Up @@ -125,29 +127,34 @@ const handler = async ({

reporter.print('')
reporter.info('Starting development server...')
reporter.print(
`The app ${chalk.bold(
config.name
)} is now available on port ${newPort}`
)
reporter.print('')

const shellStartPromise = shell.start({ port: newPort })
// start app and/or plugin, depending on flags
const shouldStartBoth =
(!shouldStartOnlyApp && !shouldStartOnlyPlugin) ||
// it would be weird to use both flags, but start both if so
(shouldStartOnlyApp && shouldStartOnlyPlugin)
const startPromises = []

if (config.entryPoints.plugin) {
const pluginPort = await detectPort(newPort + 1)
if (shouldStartBoth || shouldStartOnlyApp) {
reporter.print(
`The plugin is now available on port ${pluginPort} at /${paths.pluginLaunchPath}`
`The app ${chalk.bold(
config.name
)} is now available on port ${newPort}`
)
reporter.print('')
startPromises.push(shell.start({ port: newPort }))
}

await Promise.all([
shellStartPromise,
plugin.start({ port: pluginPort }),
])
} else {
await shellStartPromise
if (shouldStartBoth || shouldStartOnlyPlugin) {
reporter.print(
`The plugin is now available on port ${newPort} at /${paths.pluginLaunchPath}`
)
reporter.print('')
const pluginPort = shouldStartBoth ? newPort + 1 : newPort
startPromises.push(plugin.start({ port: pluginPort }))
}

await Promise.all(startPromises)
},
{
name: 'start',
Expand Down
4 changes: 1 addition & 3 deletions cli/src/lib/plugin/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const webpackConfigFactory = require('../../../config/plugin.webpack.config')

module.exports = async ({ port, config, paths }) => {
const webpackConfig = webpackConfigFactory({
// todo: change to development, but this creates a compilation error
// can read more here: https://github.com/dhis2/app-platform/pull/740/files/69411d9b61845cbd0d053f2313bdbd4e80fdf2ac#r1031576956
env: 'production',
env: 'development',
config,
paths,
})
Expand Down
1 change: 1 addition & 0 deletions examples/pwa-app/d2.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const config = {
// Uncomment this to test plugin builds:
// plugin: './src/components/VisualizationsList.js',
},
skipPluginLogic: true,
}

module.exports = config
Loading