@redhat-cloud-services/frontend-components-config 4.5.9 → 4.5.10

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/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
  - [Removed features with webpack 5](#removed-features-with-webpack-5)
8
8
  - [useProxy](#useproxy)
9
9
  - [Attributes](#attributes)
10
+ - [useChromeTemplate](#useChromeTemplate)
10
11
  - [localChrome](#localchrome)
11
12
  - [registry](#registry)
12
13
  - [Custom routes](#custom-routes)
@@ -54,6 +55,7 @@ const { config: webpackConfig, plugins } = config({
54
55
  |---------|----|-----------|
55
56
  |[useProxy](#useproxy)|`boolean`|Enables webpack proxy.|
56
57
  |[proxyURL](#proxyURL)|`string`|URL to proxy Akamai environment requests to.|
58
+ |[useChromeTemplate](#useChromeTemplate)|`boolean`|Load chrome HTMl template.|
57
59
  |[localChrome](#localChrome)|`string`|Path to your local chrome build folder.|
58
60
  |[keycloakUri](#keycloakUri)|`string`|Uri to inject into proxied chrome assets.|
59
61
  |[registry](#registry)|`(({ app, server, compiler, standaloneConfig }) => void)[]`|Express middleware to register.|
@@ -64,6 +66,24 @@ const { config: webpackConfig, plugins } = config({
64
66
  |[useCloud](#use-cloud)|`boolean`|Toggle to use old fallback to cloud.redhat.com paths instead of console.redhat.com.|
65
67
  |[target](#target)|`string`|Override `env` and `useCloud` to use a custom URI.|
66
68
 
69
+
70
+ #### useChromeTemplate
71
+
72
+ **This option will become the default. App-specific templates are deprecated**
73
+
74
+ To load chrome HTML template instead of using the APP-specific template add `useChromeTemplate` flag to your config.
75
+
76
+ ```js
77
+ const config = require('@redhat-cloud-services/frontend-components-config');
78
+
79
+ const { config: webpackConfig, plugins } = config({
80
+ rootFolder: resolve(__dirname, '../'),
81
+ useProxy: true,
82
+ useChromeTemplate: true
83
+ ...
84
+ });
85
+ ```
86
+
67
87
  #### localChrome
68
88
 
69
89
  You can also easily run you application with a local build of Chrome by adding `localChrome: <absolute_path_to_chrome_build_folder>`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config",
3
- "version": "4.5.9",
3
+ "version": "4.5.10",
4
4
  "description": "Config plugins and settings for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/config.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable camelcase */
2
2
  const path = require('path');
3
+ const fs = require('fs');
3
4
  const proxy = require('@redhat-cloud-services/frontend-components-config-utilities/proxy');
4
5
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5
6
  const searchIgnoredStyles = require('@redhat-cloud-services/frontend-components-config-utilities/search-ignored-styles');
@@ -33,7 +34,8 @@ module.exports = ({
33
34
  target,
34
35
  registry,
35
36
  client = {},
36
- bundlePfModules = false
37
+ bundlePfModules = false,
38
+ useChromeTemplate = false
37
39
  } = {}) => {
38
40
  const filenameMask = `js/[name]${useFileHash ? `.${Date.now()}.[fullhash]` : ''}.js`;
39
41
  if (betaEnv) {
@@ -41,6 +43,17 @@ module.exports = ({
41
43
  console.warn('betaEnv is deprecated in favor of env');
42
44
  }
43
45
 
46
+ const outputPath = `${rootFolder || ''}/dist`;
47
+
48
+ const copyTemplate = (chromePath) => {
49
+ const template = fs.readFileSync(`${chromePath}/index.html`, { encoding: 'utf-8' });
50
+ if (!fs.existsSync(outputPath)) {
51
+ fs.mkdirSync(outputPath);
52
+ }
53
+
54
+ fs.writeFileSync(`${outputPath}/index.html`, template);
55
+ };
56
+
44
57
  const devServerPort = typeof port === 'number' ? port : useProxy || standalone ? 1337 : 8002;
45
58
  return {
46
59
  mode: mode || (isProd ? 'production' : 'development'),
@@ -50,7 +63,7 @@ module.exports = ({
50
63
  },
51
64
  output: {
52
65
  filename: filenameMask,
53
- path: `${rootFolder || ''}/dist`,
66
+ path: outputPath,
54
67
  publicPath,
55
68
  chunkFilename: filenameMask
56
69
  },
@@ -172,7 +185,12 @@ module.exports = ({
172
185
  publicPath,
173
186
  proxyVerbose,
174
187
  target,
175
- registry
188
+ registry,
189
+ onBeforeSetupMiddleware: ({ chromePath }) => {
190
+ if (useChromeTemplate && chromePath) {
191
+ copyTemplate(chromePath);
192
+ }
193
+ }
176
194
  })
177
195
  }
178
196
  };
package/src/plugins.js CHANGED
@@ -15,7 +15,8 @@ module.exports = ({
15
15
  insights,
16
16
  modules,
17
17
  generateSourceMaps,
18
- plugins
18
+ plugins,
19
+ useChromeTemplate = false
19
20
  } = {}) => [
20
21
  ...(generateSourceMaps
21
22
  ? [
@@ -31,20 +32,30 @@ module.exports = ({
31
32
  filename: 'css/[name].[contenthash].css',
32
33
  ignoreOrder: true
33
34
  }),
34
- new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
35
- new HtmlWebpackPlugin({
36
- title: 'My App',
37
- filename: 'index.html',
38
- template: `${rootFolder || ''}/src/index.html`,
39
- inject: false,
40
- ...htmlPlugin || {}
35
+ new CleanWebpackPlugin({
36
+ cleanStaleWebpackAssets: false,
37
+ cleanOnceBeforeBuildPatterns: useChromeTemplate ? [
38
+ '**/*',
39
+ '!index.html'
40
+ ] : [
41
+ '**/*'
42
+ ]
41
43
  }),
42
- new HtmlReplaceWebpackPlugin([
43
- {
44
- pattern: '@@env',
45
- replacement: appDeployment || ''
46
- },
47
- ...replacePlugin || []
44
+ ...(useChromeTemplate ? [] : [
45
+ new HtmlWebpackPlugin({
46
+ title: 'My App',
47
+ filename: 'index.html',
48
+ template: `${rootFolder || ''}/src/index.html`,
49
+ inject: false,
50
+ ...htmlPlugin || {}
51
+ }),
52
+ new HtmlReplaceWebpackPlugin([
53
+ {
54
+ pattern: '@@env',
55
+ replacement: appDeployment || ''
56
+ },
57
+ ...replacePlugin || []
58
+ ])
48
59
  ]),
49
60
  new ProvidePlugin({
50
61
  process: 'process/browser.js',