@redhat-cloud-services/frontend-components-config 4.6.24 → 4.6.25
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 +1 -1
- package/src/plugins.js +54 -49
- package/src/plugins.test.js +18 -7
package/package.json
CHANGED
package/src/plugins.js
CHANGED
|
@@ -7,6 +7,8 @@ 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 { glob } = require('glob');
|
|
11
|
+
const path = require('path');
|
|
10
12
|
|
|
11
13
|
module.exports = ({
|
|
12
14
|
rootFolder,
|
|
@@ -19,53 +21,56 @@ module.exports = ({
|
|
|
19
21
|
plugins,
|
|
20
22
|
useChromeTemplate = true,
|
|
21
23
|
definePlugin = {},
|
|
22
|
-
} = {}) =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
24
|
+
} = {}) => {
|
|
25
|
+
const hasTsConfig = glob.sync(path.resolve(rootFolder, './{tsconfig.json,!(node_modules)/**/tsconfig.json}')).length > 0;
|
|
26
|
+
return [
|
|
27
|
+
...(generateSourceMaps
|
|
28
|
+
? [
|
|
29
|
+
new SourceMapDevToolPlugin({
|
|
30
|
+
test: 'js',
|
|
31
|
+
exclude: /(node_modules|bower_components)/i,
|
|
32
|
+
filename: 'sourcemaps/[name].[contenthash].js.map',
|
|
33
|
+
}),
|
|
34
|
+
]
|
|
35
|
+
: []),
|
|
36
|
+
new MiniCssExtractPlugin({
|
|
37
|
+
chunkFilename: 'css/[name].[contenthash].css',
|
|
38
|
+
filename: 'css/[name].[contenthash].css',
|
|
39
|
+
ignoreOrder: true,
|
|
40
|
+
}),
|
|
41
|
+
new CleanWebpackPlugin({
|
|
42
|
+
cleanStaleWebpackAssets: false,
|
|
43
|
+
cleanOnceBeforeBuildPatterns: useChromeTemplate ? ['**/*', '!index.html'] : ['**/*'],
|
|
44
|
+
}),
|
|
45
|
+
...(useChromeTemplate
|
|
46
|
+
? []
|
|
47
|
+
: [
|
|
48
|
+
new HtmlWebpackPlugin({
|
|
49
|
+
title: 'My App',
|
|
50
|
+
filename: 'index.html',
|
|
51
|
+
template: `${rootFolder || ''}/src/index.html`,
|
|
52
|
+
inject: false,
|
|
53
|
+
...(htmlPlugin || {}),
|
|
54
|
+
}),
|
|
55
|
+
new HtmlReplaceWebpackPlugin([
|
|
56
|
+
{
|
|
57
|
+
pattern: '@@env',
|
|
58
|
+
replacement: appDeployment || '',
|
|
59
|
+
},
|
|
60
|
+
...(replacePlugin || []),
|
|
61
|
+
]),
|
|
57
62
|
]),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
new DefinePlugin({
|
|
64
|
+
// we have to wrap the appname string in another string because of how define plugin explodes strings
|
|
65
|
+
CRC_APP_NAME: JSON.stringify(insights?.appname),
|
|
66
|
+
...(definePlugin || {}),
|
|
67
|
+
}),
|
|
68
|
+
new ProvidePlugin({
|
|
69
|
+
process: 'process/browser.js',
|
|
70
|
+
Buffer: ['buffer', 'Buffer'],
|
|
71
|
+
}),
|
|
72
|
+
new ChunkMapperPlugin({ modules: [...(insights ? [jsVarName(insights.appname)] : []), ...(modules || [])] }),
|
|
73
|
+
...(hasTsConfig ? [new ForkTsCheckerWebpackPlugin()] : []),
|
|
74
|
+
...(plugins || []),
|
|
75
|
+
];
|
|
76
|
+
};
|
package/src/plugins.test.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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'),
|