@openmrs/webpack-config 3.4.1-pre.98 → 4.0.1-pre.204
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/.turbo/turbo-build.log +2 -2
- package/dist/index.js +60 -9
- package/package.json +2 -2
- package/src/index.ts +67 -12
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
1
|
+
[35m@openmrs/webpack-config:build[0m: cache hit, replaying output [2mfcf9d813b6f0974b[0m
|
|
2
|
+
[35m@openmrs/webpack-config:build: [0m$ tsc
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.assetRuleConfig = exports.scssRuleConfig = exports.cssRuleConfig = exports.scriptRuleConfig = exports.additionalConfig = exports.overrides = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* This is the base webpack config for all OpenMRS 3.x modules.
|
|
9
|
+
*
|
|
10
|
+
* ## Usage
|
|
11
|
+
*
|
|
12
|
+
* You can use it as simply as
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* module.exports = require('openmrs/default-webpack-config');
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* or you can customize the configuration using merges and overrides
|
|
19
|
+
* like
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const config = require('openmrs/default-webpack-config');
|
|
23
|
+
* config.cssRuleConfig.rules = [myCustomRule];
|
|
24
|
+
* module.exports = config;
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ## Development
|
|
28
|
+
*
|
|
29
|
+
* Advice for working on this file:
|
|
30
|
+
*
|
|
31
|
+
* Don't use `yarn link` or symlinks to work on it.
|
|
32
|
+
*
|
|
33
|
+
* After you `yarn build --watch`, do something like
|
|
34
|
+
* `watch "cp -R dist /path/to/packages/esm-patient-chart-app/webpack"`
|
|
35
|
+
* and then change the webpack line from
|
|
36
|
+
* `module.exports = require('openmrs/default-webpack-config');`
|
|
37
|
+
* to
|
|
38
|
+
* `module.exports = require('./webpack');`
|
|
39
|
+
*
|
|
40
|
+
* This is because Webpack has unpredictable behavior when working with
|
|
41
|
+
* symlinked files, **even when using absolute paths**. You read that right.
|
|
42
|
+
* Telling Webpack to use `/a/b/c`? If the Webpack config is symlinked
|
|
43
|
+
* from `/d/e/`, then it *might* in *some cases* try to import `/d/e/c`.
|
|
44
|
+
*/
|
|
7
45
|
const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
|
|
8
46
|
const path_1 = require("path");
|
|
9
47
|
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
@@ -13,6 +51,7 @@ const webpack_stats_plugin_1 = require("webpack-stats-plugin");
|
|
|
13
51
|
// eslint-disable-next-line no-restricted-imports
|
|
14
52
|
const lodash_1 = require("lodash");
|
|
15
53
|
const optimize_1 = require("./optimize");
|
|
54
|
+
const semver_1 = require("semver");
|
|
16
55
|
const production = "production";
|
|
17
56
|
const { ModuleFederationPlugin } = webpack_1.container;
|
|
18
57
|
function getFrameworkVersion() {
|
|
@@ -21,7 +60,7 @@ function getFrameworkVersion() {
|
|
|
21
60
|
return `^${version}`;
|
|
22
61
|
}
|
|
23
62
|
catch (_a) {
|
|
24
|
-
return "
|
|
63
|
+
return "4.x";
|
|
25
64
|
}
|
|
26
65
|
}
|
|
27
66
|
function makeIdent(name) {
|
|
@@ -38,6 +77,9 @@ function mergeFunction(objValue, srcValue) {
|
|
|
38
77
|
return objValue.concat(srcValue);
|
|
39
78
|
}
|
|
40
79
|
}
|
|
80
|
+
function slugify(name) {
|
|
81
|
+
return name.replace(/[\/\-@]/g, "_");
|
|
82
|
+
}
|
|
41
83
|
/**
|
|
42
84
|
* This object will be merged into the webpack config.
|
|
43
85
|
* Array values will be concatenated with the existing array.
|
|
@@ -76,7 +118,7 @@ exports.scssRuleConfig = {};
|
|
|
76
118
|
exports.assetRuleConfig = {};
|
|
77
119
|
exports.default = (env, argv = {}) => {
|
|
78
120
|
const root = process.cwd();
|
|
79
|
-
const { name, peerDependencies, browser, main, types } = require((0, path_1.resolve)(root, "package.json"));
|
|
121
|
+
const { name, version, peerDependencies, browser, main, types, } = require((0, path_1.resolve)(root, "package.json"));
|
|
80
122
|
const mode = argv.mode || process.env.NODE_ENV || "development";
|
|
81
123
|
const filename = (0, path_1.basename)(browser || main);
|
|
82
124
|
const outDir = (0, path_1.dirname)(browser || main);
|
|
@@ -91,11 +133,14 @@ exports.default = (env, argv = {}) => {
|
|
|
91
133
|
},
|
|
92
134
|
},
|
|
93
135
|
};
|
|
94
|
-
const baseConfig = Object.assign({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
136
|
+
const baseConfig = Object.assign({
|
|
137
|
+
// The only `entry` in the application is the app shell. Everything else is
|
|
138
|
+
// a Webpack Module Federation "remote." This ensures that there is always
|
|
139
|
+
// only one container context--i.e., if we had an entry point per module,
|
|
140
|
+
// WMF could get confused and not resolve shared dependencies correctly.
|
|
141
|
+
output: {
|
|
142
|
+
// Use default `libraryTarget`, which is jsonp
|
|
143
|
+
publicPath: "auto",
|
|
99
144
|
path: (0, path_1.resolve)(root, outDir),
|
|
100
145
|
}, target: "web", module: {
|
|
101
146
|
rules: [
|
|
@@ -133,6 +178,7 @@ exports.default = (env, argv = {}) => {
|
|
|
133
178
|
devMiddleware: {
|
|
134
179
|
writeToDisk: true,
|
|
135
180
|
},
|
|
181
|
+
static: [(0, path_1.resolve)(root, outDir)],
|
|
136
182
|
}, performance: {
|
|
137
183
|
hints: mode === production && "warning",
|
|
138
184
|
}, plugins: [
|
|
@@ -142,14 +188,19 @@ exports.default = (env, argv = {}) => {
|
|
|
142
188
|
analyzerMode: env && env.analyze ? "server" : "disabled",
|
|
143
189
|
}),
|
|
144
190
|
new webpack_1.DefinePlugin({
|
|
191
|
+
__VERSION__: mode === production
|
|
192
|
+
? JSON.stringify(version)
|
|
193
|
+
: JSON.stringify((0, semver_1.inc)(version, "prerelease", "local")),
|
|
145
194
|
"process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
|
|
146
195
|
}),
|
|
147
196
|
new ModuleFederationPlugin({
|
|
197
|
+
// See `esm-app-shell/src/system.ts` for an explanation of how modules
|
|
198
|
+
// get loaded into the application.
|
|
148
199
|
name,
|
|
149
|
-
library: { type: "
|
|
200
|
+
library: { type: "var", name: slugify(name) },
|
|
150
201
|
filename,
|
|
151
202
|
exposes: {
|
|
152
|
-
|
|
203
|
+
"./start": srcFile,
|
|
153
204
|
},
|
|
154
205
|
shared: [
|
|
155
206
|
...Object.keys(peerDependencies),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/webpack-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1-pre.204",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"typescript": "~4.5.2",
|
|
54
54
|
"webpack": "^5.64.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "4ba2589b61d90c81eef0a21b87332b9f799f8dac"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is the base webpack config for all OpenMRS 3.x modules.
|
|
3
|
+
*
|
|
4
|
+
* ## Usage
|
|
5
|
+
*
|
|
6
|
+
* You can use it as simply as
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* module.exports = require('openmrs/default-webpack-config');
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* or you can customize the configuration using merges and overrides
|
|
13
|
+
* like
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const config = require('openmrs/default-webpack-config');
|
|
17
|
+
* config.cssRuleConfig.rules = [myCustomRule];
|
|
18
|
+
* module.exports = config;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* ## Development
|
|
22
|
+
*
|
|
23
|
+
* Advice for working on this file:
|
|
24
|
+
*
|
|
25
|
+
* Don't use `yarn link` or symlinks to work on it.
|
|
26
|
+
*
|
|
27
|
+
* After you `yarn build --watch`, do something like
|
|
28
|
+
* `watch "cp -R dist /path/to/packages/esm-patient-chart-app/webpack"`
|
|
29
|
+
* and then change the webpack line from
|
|
30
|
+
* `module.exports = require('openmrs/default-webpack-config');`
|
|
31
|
+
* to
|
|
32
|
+
* `module.exports = require('./webpack');`
|
|
33
|
+
*
|
|
34
|
+
* This is because Webpack has unpredictable behavior when working with
|
|
35
|
+
* symlinked files, **even when using absolute paths**. You read that right.
|
|
36
|
+
* Telling Webpack to use `/a/b/c`? If the Webpack config is symlinked
|
|
37
|
+
* from `/d/e/`, then it *might* in *some cases* try to import `/d/e/c`.
|
|
38
|
+
*/
|
|
1
39
|
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
|
2
40
|
import { resolve, dirname, basename } from "path";
|
|
3
41
|
import { CleanWebpackPlugin } from "clean-webpack-plugin";
|
|
@@ -7,6 +45,7 @@ import { StatsWriterPlugin } from "webpack-stats-plugin";
|
|
|
7
45
|
// eslint-disable-next-line no-restricted-imports
|
|
8
46
|
import { merge, mergeWith, isArray } from "lodash";
|
|
9
47
|
import { postProcessFile } from "./optimize";
|
|
48
|
+
import { inc } from "semver";
|
|
10
49
|
|
|
11
50
|
const production = "production";
|
|
12
51
|
const { ModuleFederationPlugin } = container;
|
|
@@ -16,7 +55,7 @@ function getFrameworkVersion() {
|
|
|
16
55
|
const { version } = require("@openmrs/esm-framework/package.json");
|
|
17
56
|
return `^${version}`;
|
|
18
57
|
} catch {
|
|
19
|
-
return "
|
|
58
|
+
return "4.x";
|
|
20
59
|
}
|
|
21
60
|
}
|
|
22
61
|
|
|
@@ -38,6 +77,10 @@ function mergeFunction(objValue: any, srcValue: any) {
|
|
|
38
77
|
}
|
|
39
78
|
}
|
|
40
79
|
|
|
80
|
+
function slugify(name) {
|
|
81
|
+
return name.replace(/[\/\-@]/g, "_");
|
|
82
|
+
}
|
|
83
|
+
|
|
41
84
|
/**
|
|
42
85
|
* This object will be merged into the webpack config.
|
|
43
86
|
* Array values will be concatenated with the existing array.
|
|
@@ -85,10 +128,14 @@ export default (
|
|
|
85
128
|
argv: Record<string, string> = {}
|
|
86
129
|
) => {
|
|
87
130
|
const root = process.cwd();
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
131
|
+
const {
|
|
132
|
+
name,
|
|
133
|
+
version,
|
|
134
|
+
peerDependencies,
|
|
135
|
+
browser,
|
|
136
|
+
main,
|
|
137
|
+
types,
|
|
138
|
+
} = require(resolve(root, "package.json"));
|
|
92
139
|
const mode = argv.mode || process.env.NODE_ENV || "development";
|
|
93
140
|
const filename = basename(browser || main);
|
|
94
141
|
const outDir = dirname(browser || main);
|
|
@@ -106,12 +153,13 @@ export default (
|
|
|
106
153
|
};
|
|
107
154
|
|
|
108
155
|
const baseConfig = {
|
|
109
|
-
entry
|
|
110
|
-
|
|
111
|
-
|
|
156
|
+
// The only `entry` in the application is the app shell. Everything else is
|
|
157
|
+
// a Webpack Module Federation "remote." This ensures that there is always
|
|
158
|
+
// only one container context--i.e., if we had an entry point per module,
|
|
159
|
+
// WMF could get confused and not resolve shared dependencies correctly.
|
|
112
160
|
output: {
|
|
113
|
-
libraryTarget
|
|
114
|
-
publicPath: "",
|
|
161
|
+
// Use default `libraryTarget`, which is jsonp
|
|
162
|
+
publicPath: "auto",
|
|
115
163
|
path: resolve(root, outDir),
|
|
116
164
|
},
|
|
117
165
|
target: "web",
|
|
@@ -166,6 +214,7 @@ export default (
|
|
|
166
214
|
devMiddleware: {
|
|
167
215
|
writeToDisk: true,
|
|
168
216
|
},
|
|
217
|
+
static: [resolve(root, outDir)],
|
|
169
218
|
},
|
|
170
219
|
performance: {
|
|
171
220
|
hints: mode === production && "warning",
|
|
@@ -177,14 +226,20 @@ export default (
|
|
|
177
226
|
analyzerMode: env && env.analyze ? "server" : "disabled",
|
|
178
227
|
}),
|
|
179
228
|
new DefinePlugin({
|
|
229
|
+
__VERSION__:
|
|
230
|
+
mode === production
|
|
231
|
+
? JSON.stringify(version)
|
|
232
|
+
: JSON.stringify(inc(version, "prerelease", "local")),
|
|
180
233
|
"process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
|
|
181
234
|
}),
|
|
182
235
|
new ModuleFederationPlugin({
|
|
236
|
+
// See `esm-app-shell/src/system.ts` for an explanation of how modules
|
|
237
|
+
// get loaded into the application.
|
|
183
238
|
name,
|
|
184
|
-
library: { type: "
|
|
239
|
+
library: { type: "var", name: slugify(name) },
|
|
185
240
|
filename,
|
|
186
241
|
exposes: {
|
|
187
|
-
|
|
242
|
+
"./start": srcFile,
|
|
188
243
|
},
|
|
189
244
|
shared: [
|
|
190
245
|
...Object.keys(peerDependencies),
|