diff --git a/adapter/src/components/ServerVersionProvider.js b/adapter/src/components/ServerVersionProvider.js index be03f6986..b707aabed 100644 --- a/adapter/src/components/ServerVersionProvider.js +++ b/adapter/src/components/ServerVersionProvider.js @@ -30,6 +30,8 @@ export const ServerVersionProvider = ({ setState({ loading: false, systemInfo }) }) .catch((e) => { + // Todo: If this is a network error, the app cannot load -- handle that gracefully here + // if (e === 'Network error') { ... } setState({ loading: false, error: e }) }) diff --git a/adapter/src/utils/api.js b/adapter/src/utils/api.js index cef437793..94e08e046 100644 --- a/adapter/src/utils/api.js +++ b/adapter/src/utils/api.js @@ -14,7 +14,7 @@ const request = (url, options) => { }) .then((response) => { if (response.status !== 200) { - reject('Request failed', response.statusText) + reject('Request failed ' + response.statusText) return } try { diff --git a/cli/package.json b/cli/package.json index b13c9e4df..81e6c5702 100644 --- a/cli/package.json +++ b/cli/package.json @@ -67,7 +67,8 @@ "terser-webpack-plugin": "^5.3.1", "webpack": "^5.41.1", "webpack-dev-server": "^4.7.4", - "workbox-build": "^6.1.5" + "workbox-build": "^6.1.5", + "workbox-webpack-plugin": "^6.5.4" }, "bin": { "d2-app-scripts": "./bin/d2-app-scripts" diff --git a/cli/src/commands/build.js b/cli/src/commands/build.js index 6049159da..226b103bd 100644 --- a/cli/src/commands/build.js +++ b/cli/src/commands/build.js @@ -132,11 +132,14 @@ const handler = async ({ await shell.build() if (config.entryPoints.plugin) { + reporter.info('Building plugin...') await plugin.build() } if (config.pwa.enabled) { - reporter.info('Injecting precache manifest...') + reporter.info( + 'Injecting supplementary precache manifest...' + ) await injectPrecacheManifest(paths, config) } } else { diff --git a/cli/src/lib/parseConfig.js b/cli/src/lib/parseConfig.js index 6de328646..998233d29 100644 --- a/cli/src/lib/parseConfig.js +++ b/cli/src/lib/parseConfig.js @@ -42,6 +42,7 @@ const validateConfig = (config) => { process.exit(1) } }) + // Todo: make sure apps with plugins have `pwa_enabled: true` in the config return true } diff --git a/cli/src/lib/plugin/build.js b/cli/src/lib/plugin/build.js index fa48f0b4a..0d4f9572b 100644 --- a/cli/src/lib/plugin/build.js +++ b/cli/src/lib/plugin/build.js @@ -8,10 +8,14 @@ const { reporter } = require('@dhis2/cli-helpers-engine') const webpack = require('webpack') const webpackConfigFactory = require('./webpack.config') -module.exports = async ({ paths }) => { +module.exports = async ({ config, paths }) => { reporter.debug('Building plugin...') - const webpackConfig = webpackConfigFactory({ env: 'production', paths }) + const webpackConfig = webpackConfigFactory({ + env: 'production', + config, + paths, + }) const compiler = webpack(webpackConfig) return new Promise((resolve, reject) => { compiler.run((err, stats) => { diff --git a/cli/src/lib/plugin/start.js b/cli/src/lib/plugin/start.js index eb98d8a64..83253e5c3 100644 --- a/cli/src/lib/plugin/start.js +++ b/cli/src/lib/plugin/start.js @@ -9,8 +9,13 @@ const webpack = require('webpack') const WebpackDevServer = require('webpack-dev-server') const webpackConfigFactory = require('./webpack.config') -module.exports = async ({ port, paths }) => { - const webpackConfig = webpackConfigFactory({ env: 'production', paths }) +module.exports = async ({ port, config, paths }) => { + const webpackConfig = webpackConfigFactory({ + // todo: change to development, but this creates a compilation error + env: 'production', + config, + paths, + }) const compiler = webpack(webpackConfig) const host = process.env.HOST || 'localhost' diff --git a/cli/src/lib/plugin/webpack.config.js b/cli/src/lib/plugin/webpack.config.js index 28dc18bf8..a5d97c2c9 100644 --- a/cli/src/lib/plugin/webpack.config.js +++ b/cli/src/lib/plugin/webpack.config.js @@ -8,7 +8,9 @@ const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent') const getPublicUrlOrPath = require('react-dev-utils/getPublicUrlOrPath') const TerserPlugin = require('terser-webpack-plugin') const webpack = require('webpack') +const WorkboxWebpackPlugin = require('workbox-webpack-plugin') const makeBabelConfig = require('../../../config/makeBabelConfig') +const { getPWAEnvVars } = require('../pwa') const getShellEnv = require('../shell/env') const babelWebpackConfig = { @@ -21,7 +23,7 @@ const babelWebpackConfig = { const cssRegex = /\.css$/ const cssModuleRegex = /\.module\.css$/ -module.exports = ({ env: webpackEnv, paths }) => { +module.exports = ({ env: webpackEnv, config, paths }) => { const isProduction = webpackEnv === 'production' const isDevelopment = !isProduction @@ -31,7 +33,12 @@ module.exports = ({ env: webpackEnv, paths }) => { process.env.PUBLIC_URL ) - const shellEnv = getShellEnv({ plugin: 'true' }) + const shellEnv = getShellEnv({ + plugin: 'true', + name: config.title, + // todo: need to make sure PWA is enabled for plugins + ...getPWAEnvVars(config), + }) // "style" loader turns CSS into JS modules that inject