@openmrs/webpack-config 5.2.1-pre.1127 → 5.2.1-pre.1133

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.
@@ -1 +1 @@
1
- @openmrs/webpack-config:build: cache hit, replaying output 03fd1405a382a816
1
+ @openmrs/webpack-config:build: cache hit, replaying output 982807e193dc48c0
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.watchConfig = exports.assetRuleConfig = exports.scssRuleConfig = exports.cssRuleConfig = exports.scriptRuleConfig = exports.additionalConfig = exports.overrides = void 0;
6
+ exports.optimizationConfig = exports.watchConfig = exports.assetRuleConfig = exports.scssRuleConfig = exports.cssRuleConfig = exports.scriptRuleConfig = exports.additionalConfig = exports.overrides = void 0;
7
7
  /**
8
8
  * This is the base webpack config for all OpenMRS 3.x modules.
9
9
  *
@@ -126,10 +126,19 @@ exports.assetRuleConfig = {};
126
126
  * Make sure to modify this object and not reassign it.
127
127
  */
128
128
  exports.watchConfig = {};
129
+ /**
130
+ * This object will be merged with the webpack optimization
131
+ * object.
132
+ * Make sure to modify this object and not reassign it.
133
+ */
134
+ exports.optimizationConfig = {};
129
135
  exports.default = (env, argv = {}) => {
130
136
  const root = process.cwd();
131
137
  const { name, version, peerDependencies, browser, main, types, } = require((0, path_1.resolve)(root, "package.json"));
132
- const mode = argv.mode || process.env.NODE_ENV || "development";
138
+ // this typing is provably incorrect, but actually works
139
+ const mode = (argv.mode ||
140
+ process.env.NODE_ENV ||
141
+ "development");
133
142
  const filename = (0, path_1.basename)(browser || main);
134
143
  const outDir = (0, path_1.dirname)(browser || main);
135
144
  const srcFile = (0, path_1.resolve)(root, browser ? main : types);
@@ -199,7 +208,14 @@ exports.default = (env, argv = {}) => {
199
208
  ignored: [".git", "test-results"],
200
209
  }, exports.watchConfig), performance: {
201
210
  hints: mode === production && "warning",
202
- }, plugins: [
211
+ }, optimization: (0, lodash_1.merge)({
212
+ // The defaults for both of these are 30; however, due to the modular nature of
213
+ // the frontend, we want each app to produce substantially
214
+ splitChunks: {
215
+ maxAsyncRequests: 3,
216
+ maxInitialRequests: 1,
217
+ },
218
+ }, exports.optimizationConfig), plugins: [
203
219
  new fork_ts_checker_webpack_plugin_1.default(),
204
220
  new clean_webpack_plugin_1.CleanWebpackPlugin(),
205
221
  new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
@@ -209,7 +225,7 @@ exports.default = (env, argv = {}) => {
209
225
  "process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
210
226
  }),
211
227
  new ModuleFederationPlugin({
212
- // See `esm-app-shell/src/load-modules.ts` for an explanation of how modules
228
+ // Look in the `esm-dynamic-loading` framework package for an explanation of how modules
213
229
  // get loaded into the application.
214
230
  name,
215
231
  library: { type: "var", name: slugify(name) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/webpack-config",
3
- "version": "5.2.1-pre.1127",
3
+ "version": "5.2.1-pre.1133",
4
4
  "license": "MPL-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -40,7 +40,13 @@ import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
40
40
  import { resolve, dirname, basename } from "path";
41
41
  import { CleanWebpackPlugin } from "clean-webpack-plugin";
42
42
  import CopyWebpackPlugin from "copy-webpack-plugin";
43
- import { DefinePlugin, container } from "webpack";
43
+ import {
44
+ DefinePlugin,
45
+ container,
46
+ type ModuleOptions,
47
+ type WebpackOptionsNormalized as WebpackConfiguration,
48
+ type RuleSetRule,
49
+ } from "webpack";
44
50
  import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
45
51
  import { StatsWriterPlugin } from "webpack-stats-plugin";
46
52
  // eslint-disable-next-line no-restricted-imports
@@ -48,6 +54,10 @@ import { merge, mergeWith, isArray } from "lodash";
48
54
  import { existsSync, statSync } from "fs";
49
55
  import { inc } from "semver";
50
56
 
57
+ type OpenmrsWebpackConfig = Omit<Partial<WebpackConfiguration>, "module"> & {
58
+ module: ModuleOptions;
59
+ };
60
+
51
61
  const production = "production";
52
62
  const { ModuleFederationPlugin } = container;
53
63
 
@@ -91,49 +101,57 @@ function fileExistsSync(name: string) {
91
101
  * Array values will be concatenated with the existing array.
92
102
  * Make sure to modify this object and not reassign it.
93
103
  */
94
- export const overrides = {};
104
+ export const overrides: Partial<OpenmrsWebpackConfig> = {};
95
105
 
96
106
  /**
97
107
  * The keys of this object will override the top-level keys
98
108
  * of the webpack config.
99
109
  * Make sure to modify this object and not reassign it.
100
110
  */
101
- export const additionalConfig = {};
111
+ export const additionalConfig: Partial<OpenmrsWebpackConfig> = {};
102
112
 
103
113
  /**
104
114
  * This object will be merged into the webpack rule governing
105
115
  * the loading of JS, JSX, TS, etc. files.
106
116
  * Make sure to modify this object and not reassign it.
107
117
  */
108
- export const scriptRuleConfig = {};
118
+ export const scriptRuleConfig: Partial<RuleSetRule> = {};
109
119
 
110
120
  /**
111
121
  * This object will be merged into the webpack rule governing
112
122
  * the loading of CSS files.
113
123
  * Make sure to modify this object and not reassign it.
114
124
  */
115
- export const cssRuleConfig = {};
125
+ export const cssRuleConfig: Partial<RuleSetRule> = {};
116
126
 
117
127
  /**
118
128
  * This object will be merged into the webpack rule governing
119
129
  * the loading of SCSS files.
120
130
  * Make sure to modify this object and not reassign it.
121
131
  */
122
- export const scssRuleConfig = {};
132
+ export const scssRuleConfig: Partial<RuleSetRule> = {};
123
133
 
124
134
  /**
125
135
  * This object will be merged into the webpack rule governing
126
136
  * the loading of static asset files.
127
137
  * Make sure to modify this object and not reassign it.
128
138
  */
129
- export const assetRuleConfig = {};
139
+ export const assetRuleConfig: Partial<RuleSetRule> = {};
130
140
 
131
141
  /**
132
142
  * This object will be merged into the webpack rule governing
133
143
  * the watch options.
134
144
  * Make sure to modify this object and not reassign it.
135
145
  */
136
- export const watchConfig = {};
146
+ export const watchConfig: Partial<WebpackConfiguration["watchOptions"]> = {};
147
+
148
+ /**
149
+ * This object will be merged with the webpack optimization
150
+ * object.
151
+ * Make sure to modify this object and not reassign it.
152
+ */
153
+ export const optimizationConfig: Partial<WebpackConfiguration["optimization"]> =
154
+ {};
137
155
 
138
156
  export default (
139
157
  env: Record<string, string>,
@@ -148,7 +166,10 @@ export default (
148
166
  main,
149
167
  types,
150
168
  } = require(resolve(root, "package.json"));
151
- const mode = argv.mode || process.env.NODE_ENV || "development";
169
+ // this typing is provably incorrect, but actually works
170
+ const mode = (argv.mode ||
171
+ process.env.NODE_ENV ||
172
+ "development") as WebpackConfiguration["mode"];
152
173
  const filename = basename(browser || main);
153
174
  const outDir = dirname(browser || main);
154
175
  const srcFile = resolve(root, browser ? main : types);
@@ -175,7 +196,7 @@ export default (
175
196
  },
176
197
  };
177
198
 
178
- const baseConfig = {
199
+ const baseConfig: OpenmrsWebpackConfig = {
179
200
  // The only `entry` in the application is the app shell. Everything else is
180
201
  // a Webpack Module Federation "remote." This ensures that there is always
181
202
  // only one container context--i.e., if we had an entry point per module,
@@ -245,6 +266,17 @@ export default (
245
266
  performance: {
246
267
  hints: mode === production && "warning",
247
268
  },
269
+ optimization: merge(
270
+ {
271
+ // The defaults for both of these are 30; however, due to the modular nature of
272
+ // the frontend, we want each app to produce substantially
273
+ splitChunks: {
274
+ maxAsyncRequests: 3,
275
+ maxInitialRequests: 1,
276
+ },
277
+ },
278
+ optimizationConfig
279
+ ),
248
280
  plugins: [
249
281
  new ForkTsCheckerWebpackPlugin(),
250
282
  new CleanWebpackPlugin(),
@@ -255,7 +287,7 @@ export default (
255
287
  "process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
256
288
  }),
257
289
  new ModuleFederationPlugin({
258
- // See `esm-app-shell/src/load-modules.ts` for an explanation of how modules
290
+ // Look in the `esm-dynamic-loading` framework package for an explanation of how modules
259
291
  // get loaded into the application.
260
292
  name,
261
293
  library: { type: "var", name: slugify(name) },