-
Notifications
You must be signed in to change notification settings - Fork 16
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: replace CRA with Vite [LIBS-598] #847
Changes from 31 commits
93799a6
554ac0b
d6b6b44
94c23eb
2ee8abf
8d1286b
ba7b412
3501da2
e30508d
c35653a
ceace1b
b196bd9
178164f
e4dd729
067ad3f
1233956
710503e
8d05509
429f61f
a256fdf
60e9b64
c20b9db
ae77246
78f8832
73a44f9
5380a6e
6f2b0bd
a0ccf72
6e34184
293933b
dd4a524
ac84759
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ const parseConfig = require('../lib/parseConfig') | |
const { isApp } = require('../lib/parseConfig') | ||
const makePaths = require('../lib/paths') | ||
const makePlugin = require('../lib/plugin') | ||
const { injectPrecacheManifest } = require('../lib/pwa') | ||
const { injectPrecacheManifest, compileServiceWorker } = require('../lib/pwa') | ||
const makeShell = require('../lib/shell') | ||
const { validatePackage } = require('../lib/validatePackage') | ||
const { handler: pack } = require('./pack.js') | ||
|
@@ -139,6 +139,9 @@ const handler = async ({ | |
} | ||
|
||
if (config.pwa.enabled) { | ||
reporter.info('Compiling service worker...') | ||
await compileServiceWorker({ config, paths, mode }) | ||
Comment on lines
+142
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, CRA compiled the service worker in production builds. We already have our own compile function that we use for dev builds, so we use that here now |
||
|
||
reporter.info( | ||
'Injecting supplementary precache manifest...' | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,11 @@ const { | |
createAppEntrypointWrapper, | ||
createPluginEntrypointWrapper, | ||
} = require('./entrypoints.js') | ||
const { | ||
extensionPattern, | ||
normalizeExtension, | ||
} = require('./extensionHelpers.js') | ||
const { extensionPattern } = require('./extensionHelpers.js') | ||
|
||
const watchFiles = ({ inputDir, outputDir, processFileCallback, watch }) => { | ||
const compileFile = async (source) => { | ||
const relative = normalizeExtension(path.relative(inputDir, source)) | ||
const relative = path.relative(inputDir, source) | ||
Comment on lines
-20
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was what broke JSX files in platform apps/libs: as an example, consider |
||
const destination = path.join(outputDir, relative) | ||
reporter.debug( | ||
`File ${relative} changed or added... dest: `, | ||
|
@@ -125,7 +122,8 @@ const compile = async ({ | |
watchFiles({ | ||
inputDir: paths.src, | ||
outputDir: outDir, | ||
processFileCallback: compileFile, | ||
// todo: handle lib compilations with Vite | ||
processFileCallback: isAppType ? copyFile : compileFile, | ||
watch, | ||
}), | ||
isAppType && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ const path = require('path') | |
const { reporter, chalk } = require('@dhis2/cli-helpers-engine') | ||
const fs = require('fs-extra') | ||
const { isApp } = require('../parseConfig') | ||
const { normalizeExtension } = require('./extensionHelpers.js') | ||
|
||
const verifyEntrypoint = ({ entrypoint, basePath, resolveModule }) => { | ||
if (!entrypoint.match(/^(\.\/)?src\//)) { | ||
|
@@ -82,12 +81,11 @@ exports.verifyEntrypoints = ({ | |
|
||
const getEntrypointWrapper = async ({ entrypoint, paths }) => { | ||
const relativeEntrypoint = entrypoint.replace(/^(\.\/)?src\//, '') | ||
const outRelativeEntrypoint = normalizeExtension(relativeEntrypoint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was also mishandling |
||
const shellAppSource = await fs.readFile(paths.shellSourceEntrypoint) | ||
|
||
return shellAppSource | ||
.toString() | ||
.replace(/'.\/D2App\/app'/g, `'./D2App/${outRelativeEntrypoint}'`) | ||
.replace(/'.\/D2App\/app\.jsx'/g, `'./D2App/${relativeEntrypoint}'`) | ||
Comment on lines
-90
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The placeholder filename in the shell is now called |
||
} | ||
|
||
exports.createAppEntrypointWrapper = async ({ entrypoint, paths }) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,25 +36,24 @@ function logManifestOutput({ count, filePaths, size, warnings }) { | |
* `workbox-build`. | ||
*/ | ||
module.exports = function injectPrecacheManifest(paths, config) { | ||
// See https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build#.injectManifest | ||
// See https://developer.chrome.com/docs/workbox/modules/workbox-build#injectmanifest_mode | ||
const injectManifestOptions = { | ||
swSrc: paths.shellBuildServiceWorker, | ||
swDest: paths.shellBuildServiceWorker, | ||
globDirectory: paths.shellBuildOutput, | ||
globPatterns: ['**/*'], | ||
// Skip index.html, (plugin.html,) and `static` directory; | ||
// CRA's workbox-webpack-plugin handles it smartly | ||
globIgnores: [ | ||
'static/**/*', | ||
paths.launchPath, | ||
paths.pluginLaunchPath, | ||
// skip moment locales -- they result in many network requests and | ||
// slow down service worker installation | ||
'**/moment-locales/*', | ||
'**/*.map', | ||
Comment on lines
-45
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few changes in this file now that it's taking over from CRA |
||
...config.pwa.caching.globsToOmitFromPrecache, | ||
], | ||
additionalManifestEntries: config.pwa.caching.additionalManifestEntries, | ||
injectionPoint: 'self.__WB_BUILD_MANIFEST', | ||
injectionPoint: 'self.__WB_MANIFEST', | ||
// Skip revision hashing for files with hash or semver in name: | ||
// (see https://regex101.com/r/z4Hy9k/1/ for RegEx details) | ||
dontCacheBustURLsMatching: /\.[a-z0-9]{8}\.|\d+\.\d+\.\d+/, | ||
// (see https://regex101.com/r/z4Hy9k/3/ for RegEx details) | ||
dontCacheBustURLsMatching: /[.-][A-Za-z0-9-_]{8}\.|\d+\.\d+\.\d+/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated for the chunks emitted from Vite's Rollup |
||
} | ||
|
||
return injectManifest(injectManifestOptions).then(logManifestOutput) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
] | ||
}, | ||
"devDependencies": { | ||
"@dhis2/cli-style": "^10.4.3", | ||
"@dhis2/cli-style": "^10.5.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"@dhis2/cli-utils-docsite": "^3.0.0", | ||
"concurrently": "^6.0.0", | ||
"serve": "^12.0.0" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See dhis2/cli-helpers-engine#225