@xh/hoist-dev-utils 8.0.0-SNAPSHOT.1710791660398 → 8.0.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.
Files changed (2) hide show
  1. package/configureWebpack.js +50 -35
  2. package/package.json +15 -15
@@ -310,8 +310,7 @@ async function configureWebpack(env) {
310
310
  path: path.resolve(appDirPath, f)
311
311
  };
312
312
  }),
313
- appNames = apps.map(it => it.name),
314
- chunkNames = getChunkCombinations(appNames.sort());
313
+ appNames = apps.map(it => it.name);
315
314
 
316
315
  // Build Webpack entry config, with keys for each JS app to be bundled.
317
316
  const appEntryPoints = {};
@@ -337,11 +336,7 @@ async function configureWebpack(env) {
337
336
  entry: appEntryPoints,
338
337
 
339
338
  output: {
340
- // Output built assets in directories per entry point / chunk.
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',
339
+ filename: '[name].[chunkhash:8].js',
345
340
  path: outPath,
346
341
  // (URL) path on which fully built app is served - i.e. root context
347
342
  publicPath: contextRoot,
@@ -359,15 +354,8 @@ async function configureWebpack(env) {
359
354
  sideEffects: false,
360
355
 
361
356
  // 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
357
  splitChunks: {
365
- chunks: 'all',
366
- name: (module, chunks) =>
367
- chunks
368
- .sort()
369
- .map(it => it.name)
370
- .join('~')
358
+ chunks: 'all'
371
359
  },
372
360
 
373
361
  // Improved debugging with readable module/chunk names.
@@ -646,12 +634,34 @@ async function configureWebpack(env) {
646
634
  title: appName,
647
635
  favicon: favicon,
648
636
  // Note: HTML template is sourced from hoist-react.
649
- template: path.resolve(hoistPath, `static/index-manifest.html`),
637
+ template: path.resolve(hoistPath, `static/index.html`),
650
638
  filename: `${jsAppName}/index.html`,
651
- // Only include chunks that contain the js app name
652
- chunks: chunkNames.filter(
653
- it => it.startsWith(jsAppName) || it.includes('~' + jsAppName)
654
- ),
639
+
640
+ // Take 0 chunks from plugin, because we collect just the ones for the jsAppName
641
+ // below in templateParameters
642
+ chunks: [],
643
+
644
+ // No need to ever cache here, either in production or development
645
+ cache: false,
646
+
647
+ // This will provide the html tag strings for just the css and js that jsAppName uses.
648
+ templateParameters: (compilation, assets, assetTags, options) => {
649
+ const tags = getFileDependenciesByEntrypoint(compilation, jsAppName);
650
+
651
+ // Output recommended by plugin example:
652
+ // https://github.com/jantimon/html-webpack-plugin/blob/main/examples/template-parameters/webpack.config.js
653
+ return {
654
+ compilation,
655
+ webpackConfig: compilation.options,
656
+ htmlWebpackPlugin: {
657
+ tags: assetTags,
658
+ files: assets,
659
+ options
660
+ },
661
+ styleTags: tags.css,
662
+ scriptTags: tags.js
663
+ };
664
+ },
655
665
  // No need to minify the HTML itself
656
666
  minify: false,
657
667
  // Flag read within template file to include apple icon.
@@ -720,7 +730,7 @@ async function configureWebpack(env) {
720
730
  : {
721
731
  host: devHost,
722
732
  port: devWebpackPort,
723
- hot: true,
733
+ hot: false, // Hot module replacement is not currently supported by Hoist, but live reload is.
724
734
  client: {overlay: devClientOverlay},
725
735
  server:
726
736
  devHttps === true
@@ -734,7 +744,8 @@ async function configureWebpack(env) {
734
744
  rewrites: appNames.map(appName => {
735
745
  return {
736
746
  from: new RegExp(`^/${appName}`),
737
- to: `/${appName}/index.html`
747
+ // helps cache busting during live reload in development
748
+ to: `/${appName}/index.html?_=${Date.now()}`
738
749
  };
739
750
  })
740
751
  }
@@ -777,7 +788,7 @@ const extraPluginsProd = terserOptions => {
777
788
  return [
778
789
  // Extract built CSS files into subdirectories by chunk / entry point name.
779
790
  new MiniCssExtractPlugin({
780
- filename: '[name]/[name].[contenthash:8].css'
791
+ filename: '[name].[contenthash:8].css'
781
792
  }),
782
793
 
783
794
  // Minify and tree-shake via Terser - https://github.com/terser/terser#readme
@@ -811,18 +822,22 @@ const extraPluginsDev = () => {
811
822
  ];
812
823
  };
813
824
 
814
- // Generate combinations for given chunkNames. Given a list of apps such as [admin, app, mobile],
815
- // possible chunk combos will be of the form admin, admin~app, app~mobile, and so on...
816
- function getChunkCombinations(appNames) {
817
- let ret = [];
818
- const combineRecursiveFn = (path, arr, sep) => {
819
- for (let i = 0; i < arr.length; i++) {
820
- const newPath = path + sep + arr[i];
821
- ret.push(newPath);
822
- combineRecursiveFn(newPath, arr.slice(i + 1), '~');
823
- }
824
- };
825
- combineRecursiveFn('', appNames, '');
825
+ // Resolves the specific script + style chunks required by a given client app entry point, to be injected into
826
+ // the generated HTML index page for that client app.
827
+ function getFileDependenciesByEntrypoint(compilation, entryName) {
828
+ const ret = {css: '', js: ''};
829
+ compilation.entrypoints
830
+ .get(entryName)
831
+ .getFiles()
832
+ .forEach(file => {
833
+ const ext = path.extname(file).slice(1);
834
+ if (ext === 'js') {
835
+ ret.js += `<script defer src="/${file}"></script>`;
836
+ } else if (ext === 'css') {
837
+ ret.css += `<link rel="stylesheet" href="/${file}" />`;
838
+ }
839
+ });
840
+
826
841
  return ret;
827
842
  }
828
843
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist-dev-utils",
3
- "version": "8.0.0-SNAPSHOT.1710791660398",
3
+ "version": "8.0.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.23.9",
16
- "@babel/plugin-proposal-decorators": "^7.23.9",
17
- "@babel/preset-env": "^7.23.9",
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": "~2.3.0",
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.14",
25
- "babel-loader": "~9.1.2",
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.0",
36
- "postcss": "~8.4.33",
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.0",
38
+ "postcss-loader": "~8.1.1",
39
39
  "rimraf": "~5.0.5",
40
- "sass": "~1.70.0",
41
- "sass-loader": "~14.1.0",
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.1",
46
+ "webpack": "~5.90.3",
47
47
  "webpack-bundle-analyzer": "~4.10.1",
48
48
  "webpack-cli": "~5.1.4",
49
- "webpack-dev-server": "~4.15.0",
50
- "webpackbar": "~6.0.0"
49
+ "webpack-dev-server": "~5.0.3",
50
+ "webpackbar": "~6.0.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "prettier": "3.x"