@xh/hoist-dev-utils 8.0.0-SNAPSHOT.1710791660398 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configureWebpack.js +99 -63
- package/package.json +15 -15
- package/static/README.md +2 -0
- package/static/index.html +26 -0
- package/static/spinner.png +0 -0
package/configureWebpack.js
CHANGED
|
@@ -81,6 +81,7 @@ try {
|
|
|
81
81
|
* @param {Object} [env.manifestConfig] - override values for manifest.json file. This controls options related to
|
|
82
82
|
* adding a mobile app to a device home screen, as well as "installing" an app via Chrome's "create shortcut"
|
|
83
83
|
* option. See https://developer.mozilla.org/en-US/docs/Web/Manifest for options.
|
|
84
|
+
* @param {string} [env.preloadBackgroundColor] - background color to use for the preloader spinner. Defaults to white.
|
|
84
85
|
* @param {string[]} [env.targetBrowsers] - array of browserslist queries specifying target browsers for Babel and CSS
|
|
85
86
|
* transpiling and processing.
|
|
86
87
|
* @param {Object} [env.babelPresetEnvOptions] - options to spread onto / override defaults passed here to the Babel
|
|
@@ -139,6 +140,7 @@ async function configureWebpack(env) {
|
|
|
139
140
|
parseChangelog = env.parseChangelog !== false,
|
|
140
141
|
favicon = env.favicon || null,
|
|
141
142
|
manifestConfig = env.manifestConfig || {},
|
|
143
|
+
preloadBackgroundColor = env.preloadBackgroundColor || 'white',
|
|
142
144
|
stats = env.stats || 'errors-only',
|
|
143
145
|
infrastructureLoggingLevel = env.infrastructureLoggingLevel || 'error',
|
|
144
146
|
targetBrowsers = env.targetBrowsers || [
|
|
@@ -226,9 +228,9 @@ async function configureWebpack(env) {
|
|
|
226
228
|
// unprocessed/unbundled and injected into HTML index files prior to any bundles.
|
|
227
229
|
const preflightScriptPath = path.resolve(hoistPath, 'static/preflight.js');
|
|
228
230
|
|
|
229
|
-
// Resolve path to spinner image
|
|
231
|
+
// Resolve path to preload spinner image to prep for copy into public assets.
|
|
230
232
|
// Displayed by generated HTML index page while JS app downloads and starts.
|
|
231
|
-
const preloadSpinnerPath = path.resolve(
|
|
233
|
+
const preloadSpinnerPath = path.resolve(hoistDevUtilsPath, 'static/spinner.png');
|
|
232
234
|
|
|
233
235
|
// Tell webpack where to look for modules when resolving imports - this is the key to getting
|
|
234
236
|
// inlineHoist mode to look in within the checked-out hoist-react project at hoistPath.
|
|
@@ -301,7 +303,7 @@ async function configureWebpack(env) {
|
|
|
301
303
|
|
|
302
304
|
// Resolve app entry points - one for each file within src/apps/ - to create bundles below.
|
|
303
305
|
const appDirPath = path.resolve(srcPath, 'apps'),
|
|
304
|
-
|
|
306
|
+
clientApps = fs
|
|
305
307
|
.readdirSync(appDirPath)
|
|
306
308
|
.filter(f => f.endsWith('.js') || f.endsWith('.ts'))
|
|
307
309
|
.map(f => {
|
|
@@ -310,20 +312,22 @@ async function configureWebpack(env) {
|
|
|
310
312
|
path: path.resolve(appDirPath, f)
|
|
311
313
|
};
|
|
312
314
|
}),
|
|
313
|
-
|
|
314
|
-
chunkNames = getChunkCombinations(appNames.sort());
|
|
315
|
+
clientAppNames = clientApps.map(it => it.name);
|
|
315
316
|
|
|
316
317
|
// Build Webpack entry config, with keys for each JS app to be bundled.
|
|
317
318
|
const appEntryPoints = {};
|
|
318
|
-
|
|
319
|
+
clientApps.forEach(clientApp => {
|
|
319
320
|
// Ensure core-js and regenerator-runtime both imported for every app bundle - they are
|
|
320
321
|
// specified as dependencies by Hoist and imported once in its polyfills.js file.
|
|
321
|
-
appEntryPoints[
|
|
322
|
+
appEntryPoints[clientApp.name] = [
|
|
323
|
+
path.resolve(hoistPath, 'static/polyfills.js'),
|
|
324
|
+
clientApp.path
|
|
325
|
+
];
|
|
322
326
|
});
|
|
323
327
|
|
|
324
328
|
logSep();
|
|
325
329
|
logMsg('🎁 App bundle entry points:');
|
|
326
|
-
|
|
330
|
+
clientAppNames.forEach(it => logMsg(` > ${it}`));
|
|
327
331
|
logSep();
|
|
328
332
|
logMsg('🤕 Something going wrong?');
|
|
329
333
|
logMsg(' > support@xh.io');
|
|
@@ -337,11 +341,7 @@ async function configureWebpack(env) {
|
|
|
337
341
|
entry: appEntryPoints,
|
|
338
342
|
|
|
339
343
|
output: {
|
|
340
|
-
|
|
341
|
-
// Use chunkhash in prod to get distinct hashes for app vs. common chunks (throws error in dev - investigate)
|
|
342
|
-
filename: prodBuild
|
|
343
|
-
? '[name]/[name].[chunkhash:8].js'
|
|
344
|
-
: '[name]/[name].[fullhash:8].js',
|
|
344
|
+
filename: '[name].[chunkhash:8].js',
|
|
345
345
|
path: outPath,
|
|
346
346
|
// (URL) path on which fully built app is served - i.e. root context
|
|
347
347
|
publicPath: contextRoot,
|
|
@@ -359,15 +359,8 @@ async function configureWebpack(env) {
|
|
|
359
359
|
sideEffects: false,
|
|
360
360
|
|
|
361
361
|
// Produce chunks for any shared imports across JS apps.
|
|
362
|
-
// Chunks are named by the JS app entry points to which they belong, concatenated with '~',
|
|
363
|
-
// e.g. `app.js`, `admin.js`, and `admin~app.js` for code shared by both apps.
|
|
364
362
|
splitChunks: {
|
|
365
|
-
chunks: 'all'
|
|
366
|
-
name: (module, chunks) =>
|
|
367
|
-
chunks
|
|
368
|
-
.sort()
|
|
369
|
-
.map(it => it.name)
|
|
370
|
-
.join('~')
|
|
363
|
+
chunks: 'all'
|
|
371
364
|
},
|
|
372
365
|
|
|
373
366
|
// Improved debugging with readable module/chunk names.
|
|
@@ -617,7 +610,7 @@ async function configureWebpack(env) {
|
|
|
617
610
|
xhAppBuild: JSON.stringify(appBuild),
|
|
618
611
|
xhBaseUrl: JSON.stringify(baseUrl),
|
|
619
612
|
xhBuildTimestamp: buildDate.getTime(),
|
|
620
|
-
xhClientApps: JSON.stringify(
|
|
613
|
+
xhClientApps: JSON.stringify(clientAppNames),
|
|
621
614
|
xhIsDevelopmentMode: !prodBuild
|
|
622
615
|
}),
|
|
623
616
|
|
|
@@ -628,8 +621,8 @@ async function configureWebpack(env) {
|
|
|
628
621
|
contextRegExp: /moment$/
|
|
629
622
|
}),
|
|
630
623
|
|
|
631
|
-
// Copy preflight script
|
|
632
|
-
// directory into the build output.
|
|
624
|
+
// Copy preflight script provided by HR, preload spinner included here in DU,
|
|
625
|
+
// plus entire /client-app/public directory into the build output.
|
|
633
626
|
new CopyWebpackPlugin({
|
|
634
627
|
patterns: _.compact([
|
|
635
628
|
{from: preflightScriptPath, to: 'public'},
|
|
@@ -641,17 +634,44 @@ async function configureWebpack(env) {
|
|
|
641
634
|
}),
|
|
642
635
|
|
|
643
636
|
// Generate HTML index pages - one per JS app.
|
|
644
|
-
...
|
|
637
|
+
...clientAppNames.map(clientAppName => {
|
|
645
638
|
return new HtmlWebpackPlugin({
|
|
646
639
|
title: appName,
|
|
647
640
|
favicon: favicon,
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
//
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
641
|
+
template: path.resolve(hoistDevUtilsPath, `static/index.html`),
|
|
642
|
+
filename: `${clientAppName}/index.html`,
|
|
643
|
+
|
|
644
|
+
// Take 0 chunks from plugin, because we collect just the ones for the jsAppName
|
|
645
|
+
// below in templateParameters
|
|
646
|
+
chunks: [],
|
|
647
|
+
|
|
648
|
+
// No need to ever cache here, either in production or development
|
|
649
|
+
cache: false,
|
|
650
|
+
|
|
651
|
+
// This will provide the html tag strings for just the css and js that jsAppName uses.
|
|
652
|
+
templateParameters: (compilation, assets, assetTags, options) => {
|
|
653
|
+
const {styleTags, scriptTags} = getFileDependenciesByEntrypoint(
|
|
654
|
+
compilation,
|
|
655
|
+
clientAppName
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
return {
|
|
659
|
+
// Base output recommended by plugin example:
|
|
660
|
+
// https://github.com/jantimon/html-webpack-plugin/blob/main/examples/template-parameters/webpack.config.js
|
|
661
|
+
compilation,
|
|
662
|
+
webpackConfig: compilation.options,
|
|
663
|
+
htmlWebpackPlugin: {
|
|
664
|
+
tags: assetTags,
|
|
665
|
+
files: assets,
|
|
666
|
+
options
|
|
667
|
+
},
|
|
668
|
+
// XH additions
|
|
669
|
+
styleTags,
|
|
670
|
+
scriptTags,
|
|
671
|
+
clientAppName,
|
|
672
|
+
preloadBackgroundColor
|
|
673
|
+
};
|
|
674
|
+
},
|
|
655
675
|
// No need to minify the HTML itself
|
|
656
676
|
minify: false,
|
|
657
677
|
// Flag read within template file to include apple icon.
|
|
@@ -659,20 +679,21 @@ async function configureWebpack(env) {
|
|
|
659
679
|
});
|
|
660
680
|
}),
|
|
661
681
|
|
|
662
|
-
// Create a manifest.json. The icon choices here work with the favicon provided
|
|
682
|
+
// Create a manifest.json for each app. The icon choices here work with the favicon provided
|
|
663
683
|
// to HtmlWebpackPlugin above to match the spec here:
|
|
664
684
|
// https://evilmartians.com/chronicles/how-to-favicon-in-2021-six-files-that-fit-most-needs
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
685
|
+
...clientAppNames.map(clientAppName => {
|
|
686
|
+
return new HoistManifestPlugin(clientAppName, {
|
|
687
|
+
name: appName,
|
|
688
|
+
short_name: appName,
|
|
689
|
+
description: `${appName} - ${appVersion}`,
|
|
690
|
+
display: 'standalone',
|
|
691
|
+
orientation: 'any',
|
|
692
|
+
background_color: preloadBackgroundColor, // ignored by Safari, but also used within index.html
|
|
693
|
+
theme_color: '#212121', // off-black from default `--xh-black` CSS var
|
|
694
|
+
icons: manifestIcons,
|
|
695
|
+
...manifestConfig
|
|
696
|
+
});
|
|
676
697
|
}),
|
|
677
698
|
|
|
678
699
|
// Insert a script tag for the (unbundled) preflight script, before all other scripts.
|
|
@@ -720,7 +741,7 @@ async function configureWebpack(env) {
|
|
|
720
741
|
: {
|
|
721
742
|
host: devHost,
|
|
722
743
|
port: devWebpackPort,
|
|
723
|
-
hot:
|
|
744
|
+
hot: false, // Hot module replacement is not currently supported by Hoist, but live reload is.
|
|
724
745
|
client: {overlay: devClientOverlay},
|
|
725
746
|
server:
|
|
726
747
|
devHttps === true
|
|
@@ -731,10 +752,11 @@ async function configureWebpack(env) {
|
|
|
731
752
|
open: env.devServerOpenPage ? [env.devServerOpenPage] : false,
|
|
732
753
|
// Support HTML5 history routes for apps, with /appName/ as the base route for each
|
|
733
754
|
historyApiFallback: {
|
|
734
|
-
rewrites:
|
|
755
|
+
rewrites: clientAppNames.map(appName => {
|
|
735
756
|
return {
|
|
736
757
|
from: new RegExp(`^/${appName}`),
|
|
737
|
-
|
|
758
|
+
// helps cache busting during live reload in development
|
|
759
|
+
to: `/${appName}/index.html?_=${Date.now()}`
|
|
738
760
|
};
|
|
739
761
|
})
|
|
740
762
|
}
|
|
@@ -746,7 +768,15 @@ async function configureWebpack(env) {
|
|
|
746
768
|
// Implementation
|
|
747
769
|
//------------------------
|
|
748
770
|
class HoistManifestPlugin {
|
|
749
|
-
constructor(content = {}) {
|
|
771
|
+
constructor(clientAppName, content = {}) {
|
|
772
|
+
this.clientAppName = clientAppName;
|
|
773
|
+
|
|
774
|
+
// We create one of these per clientApp. Default start_url to the clientApp's root, to bring user back to the
|
|
775
|
+
// clientApp from which they added the bookmark without any need for redirects, respecting possible override.
|
|
776
|
+
if (!content.start_url) {
|
|
777
|
+
content = {...content, start_url: `/${clientAppName}/`};
|
|
778
|
+
}
|
|
779
|
+
|
|
750
780
|
this.content = content;
|
|
751
781
|
}
|
|
752
782
|
|
|
@@ -763,9 +793,11 @@ class HoistManifestPlugin {
|
|
|
763
793
|
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
764
794
|
},
|
|
765
795
|
() => {
|
|
796
|
+
// Emit client-app specific manifest.json within /public, to avoid issues with deeper routes
|
|
797
|
+
// and relative paths. This is picked up by this project's /static/index.html template.
|
|
766
798
|
compilation.emitAsset(
|
|
767
|
-
|
|
768
|
-
new RawSource(JSON.stringify(this.content))
|
|
799
|
+
`/public/${this.clientAppName}/manifest.json`,
|
|
800
|
+
new RawSource(JSON.stringify(this.content, null, 2))
|
|
769
801
|
);
|
|
770
802
|
}
|
|
771
803
|
);
|
|
@@ -777,7 +809,7 @@ const extraPluginsProd = terserOptions => {
|
|
|
777
809
|
return [
|
|
778
810
|
// Extract built CSS files into subdirectories by chunk / entry point name.
|
|
779
811
|
new MiniCssExtractPlugin({
|
|
780
|
-
filename: '[name]
|
|
812
|
+
filename: '[name].[contenthash:8].css'
|
|
781
813
|
}),
|
|
782
814
|
|
|
783
815
|
// Minify and tree-shake via Terser - https://github.com/terser/terser#readme
|
|
@@ -811,18 +843,22 @@ const extraPluginsDev = () => {
|
|
|
811
843
|
];
|
|
812
844
|
};
|
|
813
845
|
|
|
814
|
-
//
|
|
815
|
-
//
|
|
816
|
-
function
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
846
|
+
// Resolves the specific script + style chunks required by a given client app entry point, to be injected into
|
|
847
|
+
// the generated HTML index page for that client app.
|
|
848
|
+
function getFileDependenciesByEntrypoint(compilation, clientAppName) {
|
|
849
|
+
const ret = {scriptTags: '', styleTags: ''};
|
|
850
|
+
compilation.entrypoints
|
|
851
|
+
.get(clientAppName)
|
|
852
|
+
.getFiles()
|
|
853
|
+
.forEach(file => {
|
|
854
|
+
const ext = path.extname(file).slice(1);
|
|
855
|
+
if (ext === 'js') {
|
|
856
|
+
ret.scriptTags += `<script defer src="/${file}"></script>`;
|
|
857
|
+
} else if (ext === 'css') {
|
|
858
|
+
ret.styleTags += `<link rel="stylesheet" href="/${file}" />`;
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
|
|
826
862
|
return ret;
|
|
827
863
|
}
|
|
828
864
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist-dev-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Utilities for configuring builds of Hoist-React client applications.",
|
|
5
5
|
"repository": "github:xh/hoist-dev-utils",
|
|
6
6
|
"homepage": "https://github.com/xh/hoist-dev-utils",
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
"static/**/*"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@babel/core": "^7.
|
|
16
|
-
"@babel/plugin-proposal-decorators": "^7.
|
|
17
|
-
"@babel/preset-env": "^7.
|
|
15
|
+
"@babel/core": "^7.24.0",
|
|
16
|
+
"@babel/plugin-proposal-decorators": "^7.24.0",
|
|
17
|
+
"@babel/preset-env": "^7.24.0",
|
|
18
18
|
"@babel/preset-react": "^7.23.3",
|
|
19
19
|
"@babel/preset-typescript": "^7.23.3",
|
|
20
|
-
"@cerner/duplicate-package-checker-webpack-plugin": "
|
|
20
|
+
"@cerner/duplicate-package-checker-webpack-plugin": "2.3.0",
|
|
21
21
|
"@types/lodash": "4.x",
|
|
22
22
|
"@types/react": "18.x",
|
|
23
23
|
"@xh/eslint-config": "^6.0",
|
|
24
|
-
"autoprefixer": "~10.4.
|
|
25
|
-
"babel-loader": "~9.1.
|
|
24
|
+
"autoprefixer": "~10.4.18",
|
|
25
|
+
"babel-loader": "~9.1.3",
|
|
26
26
|
"babel-plugin-transform-imports": "~2.0.0",
|
|
27
27
|
"case-sensitive-paths-webpack-plugin": "~2.4.0",
|
|
28
28
|
"changelog-parser": "~3.0.1",
|
|
@@ -32,22 +32,22 @@
|
|
|
32
32
|
"html-webpack-plugin": "~5.6.0",
|
|
33
33
|
"html-webpack-tags-plugin": "~3.0.2",
|
|
34
34
|
"lodash": "~4.17.21",
|
|
35
|
-
"mini-css-extract-plugin": "~2.8.
|
|
36
|
-
"postcss": "~8.4.
|
|
35
|
+
"mini-css-extract-plugin": "~2.8.1",
|
|
36
|
+
"postcss": "~8.4.35",
|
|
37
37
|
"postcss-flexbugs-fixes": "~5.0.2",
|
|
38
|
-
"postcss-loader": "~8.1.
|
|
38
|
+
"postcss-loader": "~8.1.1",
|
|
39
39
|
"rimraf": "~5.0.5",
|
|
40
|
-
"sass": "~1.
|
|
41
|
-
"sass-loader": "~14.1.
|
|
40
|
+
"sass": "~1.72.0",
|
|
41
|
+
"sass-loader": "~14.1.1",
|
|
42
42
|
"sass-material-colors": "~0.0.5",
|
|
43
43
|
"style-loader": "~3.3.2",
|
|
44
44
|
"terser-webpack-plugin": "~5.3.7",
|
|
45
45
|
"url-loader": "~4.1.1",
|
|
46
|
-
"webpack": "~5.90.
|
|
46
|
+
"webpack": "~5.90.3",
|
|
47
47
|
"webpack-bundle-analyzer": "~4.10.1",
|
|
48
48
|
"webpack-cli": "~5.1.4",
|
|
49
|
-
"webpack-dev-server": "~
|
|
50
|
-
"webpackbar": "~6.0.
|
|
49
|
+
"webpack-dev-server": "~5.0.3",
|
|
50
|
+
"webpackbar": "~6.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"prettier": "3.x"
|
package/static/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Build-related files
|
|
2
2
|
|
|
3
|
+
* `index.html` - passed to `HtmlWebpackPlugin` to be the template index.html file for each client app. Note that this
|
|
4
|
+
had been sourced from hoist-react, but as of hoist-dev-utils >= v8.1 is included with this project for simplicity.
|
|
3
5
|
* `requiredBlueprintIcons.js` - included by hoist-dev-utils >= v6.2 as a (very) streamlined replacement for the
|
|
4
6
|
full set of Blueprint JS icons otherwise required by that library. See the comment at the top of the file for
|
|
5
7
|
additional details and links.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0, shrink-to-fit=no">
|
|
6
|
+
<link rel="manifest" href="<%= webpackConfig.output.publicPath %>public/<%= clientAppName %>/manifest.json" crossorigin="use-credentials">
|
|
7
|
+
<% if (htmlWebpackPlugin.options.includeAppleIcon) { %>
|
|
8
|
+
<link rel="apple-touch-icon" href="<%= webpackConfig.output.publicPath %>public/apple-touch-icon.png">
|
|
9
|
+
<% } %>
|
|
10
|
+
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
11
|
+
<%= styleTags %>
|
|
12
|
+
</head>
|
|
13
|
+
<body class="xh-app" style="margin: 0">
|
|
14
|
+
|
|
15
|
+
<noscript>
|
|
16
|
+
This application requires that JavaScript be enabled for this site in your browser.
|
|
17
|
+
</noscript>
|
|
18
|
+
|
|
19
|
+
<div id="xh-preload-spinner" style="height: 100vh; width: 100vw; display: flex; align-items: center; justify-content: center; background-color: <%= preloadBackgroundColor %>">
|
|
20
|
+
<img src="<%= webpackConfig.output.publicPath %>public/spinner.png" style="width: 50px; height: 50px;">
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<div id="xh-root"></div>
|
|
24
|
+
<%= scriptTags %>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
Binary file
|