Skip to content

Commit da6f1e9

Browse files
committed
chore: clean up webpack configs
1 parent 9a8303d commit da6f1e9

File tree

6 files changed

+40
-38
lines changed

6 files changed

+40
-38
lines changed

examples/frontend-webpack-project/webpack.config.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const { default: AppConfigPlugin } = require('@app-config/webpack');
55
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
66
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
77

8+
const appConfigOptions = {
9+
headerInjection: true,
10+
};
11+
812
module.exports = {
913
entry: './src/index.ts',
1014
output: {
@@ -21,11 +25,11 @@ module.exports = {
2125
},
2226
{
2327
test: AppConfigPlugin.regex,
24-
use: { loader: AppConfigPlugin.loader, options: { headerInjection: true } },
28+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
2529
},
2630
],
2731
},
28-
plugins: [new HtmlPlugin(), new AppConfigPlugin({ headerInjection: true })],
32+
plugins: [new HtmlPlugin(), new AppConfigPlugin(appConfigOptions)],
2933
devServer: {
3034
host: '0.0.0.0',
3135
port: 8080,

tests/webpack-projects/cypress-plugin/webpack.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const path = require('path');
22
const HtmlPlugin = require('html-webpack-plugin');
33
const { default: AppConfigPlugin } = require('@app-config/webpack');
44

5-
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
6-
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
5+
const appConfigOptions = {
6+
headerInjection: true,
7+
};
78

89
module.exports = {
910
entry: './src/index.ts',
@@ -21,11 +22,11 @@ module.exports = {
2122
},
2223
{
2324
test: AppConfigPlugin.regex,
24-
use: { loader: AppConfigPlugin.loader, options: { headerInjection: true } },
25+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
2526
},
2627
],
2728
},
28-
plugins: [new HtmlPlugin(), new AppConfigPlugin({ headerInjection: true })],
29+
plugins: [new HtmlPlugin(), new AppConfigPlugin(appConfigOptions)],
2930
devServer: {
3031
host: '0.0.0.0',
3132
port: 8991,

tests/webpack-projects/extending-other-files/webpack.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ const path = require('path');
22
const HtmlPlugin = require('html-webpack-plugin');
33
const { default: AppConfigPlugin } = require('@app-config/webpack');
44

5-
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
6-
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
5+
const appConfigOptions = {};
76

87
module.exports = {
98
entry: './src/index.ts',
@@ -21,11 +20,11 @@ module.exports = {
2120
},
2221
{
2322
test: AppConfigPlugin.regex,
24-
use: { loader: AppConfigPlugin.loader },
23+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
2524
},
2625
],
2726
},
28-
plugins: [new HtmlPlugin(), new AppConfigPlugin()],
27+
plugins: [new HtmlPlugin(), new AppConfigPlugin(appConfigOptions)],
2928
devServer: {
3029
host: '0.0.0.0',
3130
port: 8994,

tests/webpack-projects/query-parameter-overrides/webpack.config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ const path = require('path');
22
const HtmlPlugin = require('html-webpack-plugin');
33
const { default: AppConfigPlugin } = require('@app-config/webpack');
44

5-
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
6-
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
5+
const appConfigOptions = {};
76

87
module.exports = {
98
entry: './src/index.ts',
@@ -21,11 +20,11 @@ module.exports = {
2120
},
2221
{
2322
test: AppConfigPlugin.regex,
24-
use: { loader: AppConfigPlugin.loader, options: { headerInjection: true } },
23+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
2524
},
2625
],
2726
},
28-
plugins: [new HtmlPlugin(), new AppConfigPlugin({ headerInjection: true })],
27+
plugins: [new HtmlPlugin(), new AppConfigPlugin(appConfigOptions)],
2928
devServer: {
3029
host: '0.0.0.0',
3130
port: 8990,

tests/webpack-projects/two-app-config-sources/webpack.config.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@ const path = require('path');
22
const HtmlPlugin = require('html-webpack-plugin');
33
const { default: AppConfigPlugin } = require('@app-config/webpack');
44

5-
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
6-
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
5+
const appConfigOptions = {
6+
headerInjection: true,
7+
};
8+
9+
const appConfigStaticOptions = {
10+
noGlobal: true,
11+
intercept: /app-config-static/,
12+
loading: {
13+
fileNameBase: 'app-config-static',
14+
},
15+
schemaLoading: {
16+
fileNameBase: 'app-config-static.schema',
17+
},
18+
};
719

820
module.exports = {
921
entry: './src/index.ts',
@@ -23,33 +35,19 @@ module.exports = {
2335
test: /app-config-static/,
2436
use: {
2537
loader: AppConfigPlugin.loader,
26-
options: {
27-
noGlobal: true,
28-
loading: {
29-
fileNameBase: 'app-config-static',
30-
},
31-
},
38+
options: appConfigStaticOptions,
3239
},
3340
},
3441
{
3542
test: AppConfigPlugin.regex,
36-
use: { loader: AppConfigPlugin.loader, options: { headerInjection: true } },
43+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
3744
},
3845
],
3946
},
4047
plugins: [
4148
new HtmlPlugin(),
42-
new AppConfigPlugin({ headerInjection: true }),
43-
new AppConfigPlugin({
44-
noGlobal: true,
45-
intercept: /app-config-static/,
46-
loading: {
47-
fileNameBase: 'app-config-static',
48-
},
49-
schemaLoading: {
50-
fileNameBase: 'app-config-static.schema',
51-
},
52-
}),
49+
new AppConfigPlugin(appConfigOptions),
50+
new AppConfigPlugin(appConfigStaticOptions),
5351
],
5452
devServer: {
5553
host: '0.0.0.0',

tests/webpack-projects/webpack5/webpack.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const path = require('path');
22
const HtmlPlugin = require('html-webpack-plugin');
33
const { default: AppConfigPlugin } = require('@app-config/webpack');
44

5-
// Important parts are in module->rules (the AppConfigPlugin.loader), and plugins
6-
// AppConfigPlugin relies on HtmlPlugin (html-webpack-plugin), when using headerInjection
5+
const appConfigOptions = {
6+
headerInjection: true,
7+
};
78

89
module.exports = {
910
entry: './src/index.ts',
@@ -21,11 +22,11 @@ module.exports = {
2122
},
2223
{
2324
test: AppConfigPlugin.regex,
24-
use: { loader: AppConfigPlugin.loader, options: { headerInjection: true } },
25+
use: { loader: AppConfigPlugin.loader, options: appConfigOptions },
2526
},
2627
],
2728
},
28-
plugins: [new HtmlPlugin(), new AppConfigPlugin({ headerInjection: true })],
29+
plugins: [new HtmlPlugin(), new AppConfigPlugin(appConfigOptions)],
2930
devServer: {
3031
host: '0.0.0.0',
3132
port: 8995,

0 commit comments

Comments
 (0)