@openmrs/webpack-config 3.3.2-pre.9 → 4.0.0-pre.0
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/.turbo/turbo-lint.log +2 -0
- package/.turbo/turbo-test.log +3 -0
- package/dist/dynamic-register.js +81 -0
- package/dist/index.js +55 -8
- package/dist/optimize.js +0 -0
- package/package.json +2 -2
- package/src/index.ts +54 -8
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[
|
|
2
|
-
[
|
|
1
|
+
[34m@openmrs/webpack-config:build: [0mcache hit, replaying output [2mc1cdecd2e269d1cd[0m
|
|
2
|
+
[34m@openmrs/webpack-config:build: [0m$ tsc
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.postProcessFile = exports.transformFile = void 0;
|
|
23
|
+
const types = __importStar(require("@babel/types"));
|
|
24
|
+
const core_1 = require("@babel/core");
|
|
25
|
+
const fs_1 = require("fs");
|
|
26
|
+
const path_1 = require("path");
|
|
27
|
+
function isUnique(current, index, arr) {
|
|
28
|
+
return arr.indexOf(current) === index;
|
|
29
|
+
}
|
|
30
|
+
function getFiles(manifest) {
|
|
31
|
+
const files = [];
|
|
32
|
+
manifest.chunks.forEach((chunk) => {
|
|
33
|
+
files.push(...chunk.files);
|
|
34
|
+
});
|
|
35
|
+
return files.filter(isUnique);
|
|
36
|
+
}
|
|
37
|
+
function transformFile(filename) {
|
|
38
|
+
var _a;
|
|
39
|
+
const root = (0, path_1.dirname)(filename);
|
|
40
|
+
const manifest = require(`${filename}.buildmanifest.json`);
|
|
41
|
+
const files = getFiles(manifest);
|
|
42
|
+
const code = (0, fs_1.readFileSync)(filename, "utf8");
|
|
43
|
+
const result = (0, core_1.transformSync)(code, {
|
|
44
|
+
filename,
|
|
45
|
+
sourceType: "script",
|
|
46
|
+
presets: ["minify"],
|
|
47
|
+
plugins: [
|
|
48
|
+
() => ({
|
|
49
|
+
visitor: {
|
|
50
|
+
Property(path) { },
|
|
51
|
+
CallExpression(path) {
|
|
52
|
+
const node = path.node;
|
|
53
|
+
if (types.isMemberExpression(node.callee) &&
|
|
54
|
+
types.isIdentifier(node.callee.object, { name: "System" }) &&
|
|
55
|
+
types.isIdentifier(node.callee.property, {
|
|
56
|
+
name: "register",
|
|
57
|
+
}) &&
|
|
58
|
+
node.arguments.length === 3 &&
|
|
59
|
+
types.isFunctionExpression(node.arguments[2])) {
|
|
60
|
+
path
|
|
61
|
+
.get("arguments.2.body")
|
|
62
|
+
.unshiftContainer("body", types.variableDeclaration("var", [
|
|
63
|
+
types.variableDeclarator(types.identifier("undefined")),
|
|
64
|
+
]));
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
return [(_a = result === null || result === void 0 ? void 0 : result.code) === null || _a === void 0 ? void 0 : _a.split('"use strict";').join(""), code];
|
|
72
|
+
}
|
|
73
|
+
exports.transformFile = transformFile;
|
|
74
|
+
function postProcessFile(fn) {
|
|
75
|
+
const [result, original] = transformFile(fn);
|
|
76
|
+
if (result && original) {
|
|
77
|
+
(0, fs_1.writeFileSync)(fn.replace(".js", ".old"), original, "utf8");
|
|
78
|
+
(0, fs_1.writeFileSync)(fn.replace(".js", ".js"), result, "utf8");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.postProcessFile = postProcessFile;
|
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");
|
|
@@ -21,7 +59,7 @@ function getFrameworkVersion() {
|
|
|
21
59
|
return `^${version}`;
|
|
22
60
|
}
|
|
23
61
|
catch (_a) {
|
|
24
|
-
return "
|
|
62
|
+
return "4.x";
|
|
25
63
|
}
|
|
26
64
|
}
|
|
27
65
|
function makeIdent(name) {
|
|
@@ -38,6 +76,9 @@ function mergeFunction(objValue, srcValue) {
|
|
|
38
76
|
return objValue.concat(srcValue);
|
|
39
77
|
}
|
|
40
78
|
}
|
|
79
|
+
function slugify(name) {
|
|
80
|
+
return name.replace(/[\/\-@]/g, "_");
|
|
81
|
+
}
|
|
41
82
|
/**
|
|
42
83
|
* This object will be merged into the webpack config.
|
|
43
84
|
* Array values will be concatenated with the existing array.
|
|
@@ -91,11 +132,14 @@ exports.default = (env, argv = {}) => {
|
|
|
91
132
|
},
|
|
92
133
|
},
|
|
93
134
|
};
|
|
94
|
-
const baseConfig = Object.assign({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
135
|
+
const baseConfig = Object.assign({
|
|
136
|
+
// The only `entry` in the application is the app shell. Everything else is
|
|
137
|
+
// a Webpack Module Federation "remote." This ensures that there is always
|
|
138
|
+
// only one container context--i.e., if we had an entry point per module,
|
|
139
|
+
// WMF could get confused and not resolve shared dependencies correctly.
|
|
140
|
+
output: {
|
|
141
|
+
// Use deafult `libraryTarget`, which is jsonp
|
|
142
|
+
publicPath: "auto",
|
|
99
143
|
path: (0, path_1.resolve)(root, outDir),
|
|
100
144
|
}, target: "web", module: {
|
|
101
145
|
rules: [
|
|
@@ -133,6 +177,7 @@ exports.default = (env, argv = {}) => {
|
|
|
133
177
|
devMiddleware: {
|
|
134
178
|
writeToDisk: true,
|
|
135
179
|
},
|
|
180
|
+
static: [(0, path_1.resolve)(root, outDir)],
|
|
136
181
|
}, performance: {
|
|
137
182
|
hints: mode === production && "warning",
|
|
138
183
|
}, plugins: [
|
|
@@ -145,11 +190,13 @@ exports.default = (env, argv = {}) => {
|
|
|
145
190
|
"process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
|
|
146
191
|
}),
|
|
147
192
|
new ModuleFederationPlugin({
|
|
193
|
+
// See `esm-app-shell/src/system.ts` for an explanation of how modules
|
|
194
|
+
// get loaded into the application.
|
|
148
195
|
name,
|
|
149
|
-
library: { type: "
|
|
196
|
+
library: { type: "var", name: slugify(name) },
|
|
150
197
|
filename,
|
|
151
198
|
exposes: {
|
|
152
|
-
|
|
199
|
+
"./start": srcFile,
|
|
153
200
|
},
|
|
154
201
|
shared: [
|
|
155
202
|
...Object.keys(peerDependencies),
|
package/dist/optimize.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/webpack-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-pre.0",
|
|
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": "254a7226212aac82df4434639b2584e24ac240e4"
|
|
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";
|
|
@@ -16,7 +54,7 @@ function getFrameworkVersion() {
|
|
|
16
54
|
const { version } = require("@openmrs/esm-framework/package.json");
|
|
17
55
|
return `^${version}`;
|
|
18
56
|
} catch {
|
|
19
|
-
return "
|
|
57
|
+
return "4.x";
|
|
20
58
|
}
|
|
21
59
|
}
|
|
22
60
|
|
|
@@ -38,6 +76,10 @@ function mergeFunction(objValue: any, srcValue: any) {
|
|
|
38
76
|
}
|
|
39
77
|
}
|
|
40
78
|
|
|
79
|
+
function slugify(name) {
|
|
80
|
+
return name.replace(/[\/\-@]/g, "_");
|
|
81
|
+
}
|
|
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.
|
|
@@ -106,12 +148,13 @@ export default (
|
|
|
106
148
|
};
|
|
107
149
|
|
|
108
150
|
const baseConfig = {
|
|
109
|
-
entry
|
|
110
|
-
|
|
111
|
-
|
|
151
|
+
// The only `entry` in the application is the app shell. Everything else is
|
|
152
|
+
// a Webpack Module Federation "remote." This ensures that there is always
|
|
153
|
+
// only one container context--i.e., if we had an entry point per module,
|
|
154
|
+
// WMF could get confused and not resolve shared dependencies correctly.
|
|
112
155
|
output: {
|
|
113
|
-
libraryTarget
|
|
114
|
-
publicPath: "",
|
|
156
|
+
// Use deafult `libraryTarget`, which is jsonp
|
|
157
|
+
publicPath: "auto",
|
|
115
158
|
path: resolve(root, outDir),
|
|
116
159
|
},
|
|
117
160
|
target: "web",
|
|
@@ -166,6 +209,7 @@ export default (
|
|
|
166
209
|
devMiddleware: {
|
|
167
210
|
writeToDisk: true,
|
|
168
211
|
},
|
|
212
|
+
static: [resolve(root, outDir)],
|
|
169
213
|
},
|
|
170
214
|
performance: {
|
|
171
215
|
hints: mode === production && "warning",
|
|
@@ -180,11 +224,13 @@ export default (
|
|
|
180
224
|
"process.env.FRAMEWORK_VERSION": JSON.stringify(frameworkVersion),
|
|
181
225
|
}),
|
|
182
226
|
new ModuleFederationPlugin({
|
|
227
|
+
// See `esm-app-shell/src/system.ts` for an explanation of how modules
|
|
228
|
+
// get loaded into the application.
|
|
183
229
|
name,
|
|
184
|
-
library: { type: "
|
|
230
|
+
library: { type: "var", name: slugify(name) },
|
|
185
231
|
filename,
|
|
186
232
|
exposes: {
|
|
187
|
-
|
|
233
|
+
"./start": srcFile,
|
|
188
234
|
},
|
|
189
235
|
shared: [
|
|
190
236
|
...Object.keys(peerDependencies),
|