@redhat-cloud-services/frontend-components-config 4.6.24 → 4.6.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redhat-cloud-services/frontend-components-config",
3
- "version": "4.6.24",
3
+ "version": "4.6.26",
4
4
  "description": "Config plugins and settings for RedHat Cloud Services project.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -20,7 +20,8 @@
20
20
  },
21
21
  "homepage": "https://github.com/RedHatInsights/frontend-components/tree/master/packages/config#readme",
22
22
  "dependencies": {
23
- "@redhat-cloud-services/frontend-components-config-utilities": "^1.5.23",
23
+ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.8",
24
+ "@redhat-cloud-services/frontend-components-config-utilities": "^1.5.24",
24
25
  "assert": "^2.0.0",
25
26
  "axios": "^0.27.2",
26
27
  "babel-loader": "^8.2.5",
@@ -45,6 +46,7 @@
45
46
  "lodash": "^4.17.21",
46
47
  "path-browserify": "^1.0.1",
47
48
  "process": "^0.11.10",
49
+ "react-refresh": "^0.14.0",
48
50
  "sass": "^1.55.0",
49
51
  "sass-loader": "^11.1.1",
50
52
  "source-map-loader": "^3.0.1",
package/src/config.js CHANGED
@@ -41,8 +41,9 @@ module.exports = ({
41
41
  useDevBuild = true,
42
42
  useCache = false,
43
43
  cacheConfig = {},
44
+ _unstableHotReload = false,
44
45
  } = {}) => {
45
- const filenameMask = `js/[name]${useFileHash ? `.${Date.now()}.[fullhash]` : ''}.js`;
46
+ const filenameMask = `js/[name]${!_unstableHotReload && useFileHash ? `.${Date.now()}.[fullhash]` : ''}.js`;
46
47
  if (betaEnv) {
47
48
  env = `${betaEnv}-beta`;
48
49
  console.warn('betaEnv is deprecated in favor of env');
@@ -75,15 +76,29 @@ module.exports = ({
75
76
  },
76
77
  }
77
78
  : {}),
78
- entry: {
79
- App: appEntry,
80
- },
79
+ entry: _unstableHotReload
80
+ ? {
81
+ main: appEntry,
82
+ vendors: ['react', 'react-dom', 'react-refresh/runtime'],
83
+ }
84
+ : {
85
+ App: appEntry,
86
+ },
81
87
  output: {
82
88
  filename: filenameMask,
83
89
  path: outputPath,
84
90
  publicPath,
85
91
  chunkFilename: filenameMask,
86
92
  },
93
+ ...(_unstableHotReload
94
+ ? {
95
+ optimization: {
96
+ // for HMR all runtime chunks must be in a single file
97
+ runtimeChunk: 'single',
98
+ removeEmptyChunks: true,
99
+ },
100
+ }
101
+ : {}),
87
102
  module: {
88
103
  rules: [
89
104
  {
@@ -179,7 +194,8 @@ module.exports = ({
179
194
  port: devServerPort,
180
195
  https: https || Boolean(useProxy),
181
196
  host: '0.0.0.0', // This shares on local network. Needed for docker.host.internal
182
- hot: false, // Use livereload instead of HMR which is spotty with federated modules
197
+ hot: _unstableHotReload, // Use livereload instead of HMR which is spotty with federated modules
198
+ liveReload: !_unstableHotReload,
183
199
  allowedHosts: 'all',
184
200
  // https://github.com/bripkens/connect-history-api-fallback
185
201
  historyApiFallback: {
@@ -48,6 +48,7 @@ describe('should create dummy config with no options', () => {
48
48
  host: '0.0.0.0',
49
49
  port: 8002,
50
50
  hot: false,
51
+ liveReload: true,
51
52
  allowedHosts: 'all',
52
53
  historyApiFallback: {
53
54
  rewrites: [
package/src/plugins.js CHANGED
@@ -7,6 +7,9 @@ const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
7
7
  const ChunkMapperPlugin = require('@redhat-cloud-services/frontend-components-config-utilities/chunk-mapper');
8
8
  const jsVarName = require('@redhat-cloud-services/frontend-components-config-utilities/jsVarName');
9
9
  const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
10
+ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
11
+ const { glob } = require('glob');
12
+ const path = require('path');
10
13
 
11
14
  module.exports = ({
12
15
  rootFolder,
@@ -19,53 +22,60 @@ module.exports = ({
19
22
  plugins,
20
23
  useChromeTemplate = true,
21
24
  definePlugin = {},
22
- } = {}) => [
23
- ...(generateSourceMaps
24
- ? [
25
- new SourceMapDevToolPlugin({
26
- test: 'js',
27
- exclude: /(node_modules|bower_components)/i,
28
- filename: 'sourcemaps/[name].[contenthash].js.map',
29
- }),
30
- ]
31
- : []),
32
- new MiniCssExtractPlugin({
33
- chunkFilename: 'css/[name].[contenthash].css',
34
- filename: 'css/[name].[contenthash].css',
35
- ignoreOrder: true,
36
- }),
37
- new CleanWebpackPlugin({
38
- cleanStaleWebpackAssets: false,
39
- cleanOnceBeforeBuildPatterns: useChromeTemplate ? ['**/*', '!index.html'] : ['**/*'],
40
- }),
41
- ...(useChromeTemplate
42
- ? []
43
- : [
44
- new HtmlWebpackPlugin({
45
- title: 'My App',
46
- filename: 'index.html',
47
- template: `${rootFolder || ''}/src/index.html`,
48
- inject: false,
49
- ...(htmlPlugin || {}),
50
- }),
51
- new HtmlReplaceWebpackPlugin([
52
- {
53
- pattern: '@@env',
54
- replacement: appDeployment || '',
55
- },
56
- ...(replacePlugin || []),
25
+ _unstableHotReload = false,
26
+ useFileHash = true,
27
+ } = {}) => {
28
+ const hasTsConfig = glob.sync(path.resolve(rootFolder, './{tsconfig.json,!(node_modules)/**/tsconfig.json}')).length > 0;
29
+ const fileHash = !_unstableHotReload && useFileHash;
30
+ return [
31
+ ...(generateSourceMaps
32
+ ? [
33
+ new SourceMapDevToolPlugin({
34
+ test: 'js',
35
+ exclude: /(node_modules|bower_components)/i,
36
+ filename: fileHash ? 'sourcemaps/[name].js.map' : 'sourcemaps/[name].[contenthash].js.map',
37
+ }),
38
+ ]
39
+ : []),
40
+ new MiniCssExtractPlugin({
41
+ chunkFilename: fileHash ? 'css/[name].css' : 'css/[name].[contenthash].css',
42
+ filename: fileHash ? 'css/[name].css' : 'css/[name].[contenthash].css',
43
+ ignoreOrder: true,
44
+ }),
45
+ new CleanWebpackPlugin({
46
+ cleanStaleWebpackAssets: false,
47
+ cleanOnceBeforeBuildPatterns: useChromeTemplate ? ['**/*', '!index.html'] : ['**/*'],
48
+ }),
49
+ ...(useChromeTemplate
50
+ ? []
51
+ : [
52
+ new HtmlWebpackPlugin({
53
+ title: 'My App',
54
+ filename: 'index.html',
55
+ template: `${rootFolder || ''}/src/index.html`,
56
+ inject: false,
57
+ ...(htmlPlugin || {}),
58
+ }),
59
+ new HtmlReplaceWebpackPlugin([
60
+ {
61
+ pattern: '@@env',
62
+ replacement: appDeployment || '',
63
+ },
64
+ ...(replacePlugin || []),
65
+ ]),
57
66
  ]),
58
- ]),
59
- new DefinePlugin({
60
- // we have to wrap the appname string in another string because of how define plugin explodes strings
61
- CRC_APP_NAME: JSON.stringify(insights?.appname),
62
- ...(definePlugin || {}),
63
- }),
64
- new ProvidePlugin({
65
- process: 'process/browser.js',
66
- Buffer: ['buffer', 'Buffer'],
67
- }),
68
- new ChunkMapperPlugin({ modules: [...(insights ? [jsVarName(insights.appname)] : []), ...(modules || [])] }),
69
- new ForkTsCheckerWebpackPlugin(),
70
- ...(plugins || []),
71
- ];
67
+ new DefinePlugin({
68
+ // we have to wrap the appname string in another string because of how define plugin explodes strings
69
+ CRC_APP_NAME: JSON.stringify(insights?.appname),
70
+ ...(definePlugin || {}),
71
+ }),
72
+ new ProvidePlugin({
73
+ process: 'process/browser.js',
74
+ Buffer: ['buffer', 'Buffer'],
75
+ }),
76
+ new ChunkMapperPlugin({ _unstableHotReload, modules: [...(insights ? [jsVarName(insights.appname)] : []), ...(modules || [])] }),
77
+ ...(hasTsConfig ? [new ForkTsCheckerWebpackPlugin()] : []),
78
+ ...(plugins || []),
79
+ ...(_unstableHotReload ? [new ReactRefreshWebpackPlugin()] : []),
80
+ ];
81
+ };
@@ -1,23 +1,31 @@
1
1
  import plugins from './plugins';
2
+ import path from 'path';
2
3
 
3
4
  const HTML_WEBPACK = 2;
4
5
  const REPLACE = 3;
5
6
  const DEFINE_PLUGIN = 4;
6
7
 
7
8
  describe('plugins generations, no option', () => {
8
- const enabledPlugins = plugins({ useChromeTemplate: false });
9
+ const enabledPlugins = plugins({ useChromeTemplate: false, rootFolder: '/foo/bar' });
9
10
 
10
11
  it('should generate plugins', () => {
11
- expect(enabledPlugins.length).toBe(8);
12
+ expect(enabledPlugins.length).toBe(7);
12
13
  });
13
14
 
14
15
  it('should generate plugins with sourceMaps', () => {
15
- const enabledPlugins = plugins({ generateSourceMaps: true, useChromeTemplate: false });
16
- expect(enabledPlugins.length).toBe(9);
16
+ const enabledPlugins = plugins({ generateSourceMaps: true, useChromeTemplate: false, rootFolder: '/foo/bar' });
17
+ expect(enabledPlugins.length).toBe(8);
17
18
  });
18
19
 
19
20
  it('should generate correct template path for HtmlWebpackPlugin', () => {
20
- expect(enabledPlugins[HTML_WEBPACK].userOptions.template).toBe('/src/index.html');
21
+ expect(enabledPlugins[HTML_WEBPACK].userOptions.template).toBe('/foo/bar/src/index.html');
22
+ });
23
+ });
24
+
25
+ describe('TS for plugins', () => {
26
+ const pluginsWithTs = plugins({ generateSourceMaps: true, useChromeTemplate: false, rootFolder: path.resolve(__dirname, '../../../') });
27
+ it('should have TSForkPlugin and 9 plugins in todal', () => {
28
+ expect(pluginsWithTs).toHaveLength(9);
21
29
  });
22
30
  });
23
31
 
@@ -30,7 +38,7 @@ describe('rootFolder', () => {
30
38
  });
31
39
 
32
40
  describe('appDeployment', () => {
33
- const enabledPlugins = plugins({ appDeployment: '/test/folder', useChromeTemplate: false });
41
+ const enabledPlugins = plugins({ appDeployment: '/test/folder', useChromeTemplate: false, rootFolder: '/foo/bar' });
34
42
 
35
43
  it('should replace correct string', () => {
36
44
  enabledPlugins[REPLACE].replace({ html: 'string @@env' }, (_, { html }) => expect(html).toBe('string /test/folder'));
@@ -38,13 +46,14 @@ describe('appDeployment', () => {
38
46
  });
39
47
 
40
48
  it('htmlPlugin should update', () => {
41
- const enabledPlugins = plugins({ htmlPlugin: { title: 'myTitle' }, useChromeTemplate: false });
49
+ const enabledPlugins = plugins({ htmlPlugin: { title: 'myTitle' }, useChromeTemplate: false, rootFolder: '/foo/bar' });
42
50
  expect(enabledPlugins[HTML_WEBPACK].userOptions.title).toBe('myTitle');
43
51
  });
44
52
 
45
53
  it('replacePlugin should update', () => {
46
54
  const enabledPlugins = plugins({
47
55
  useChromeTemplate: false,
56
+ rootFolder: '/foo/bar',
48
57
  replacePlugin: [
49
58
  {
50
59
  pattern: '@@another',
@@ -58,6 +67,7 @@ it('replacePlugin should update', () => {
58
67
  it('definePlugin should have default replace of CRC_APP_NAME', () => {
59
68
  const enabledPlugins = plugins({
60
69
  useChromeTemplate: false,
70
+ rootFolder: '/foo/bar',
61
71
  insights: { appname: 'test_app' },
62
72
  });
63
73
  expect(enabledPlugins[DEFINE_PLUGIN].definitions.CRC_APP_NAME).toBe('"test_app"');
@@ -65,6 +75,7 @@ it('definePlugin should have default replace of CRC_APP_NAME', () => {
65
75
 
66
76
  it('definePlugin should update', () => {
67
77
  const enabledPlugins = plugins({
78
+ rootFolder: '/foo/bar',
68
79
  useChromeTemplate: false,
69
80
  definePlugin: {
70
81
  SOME_VAR: JSON.stringify('test_val'),