@genesislcap/webpack-builder 14.26.8-alpha-64bb9e2.0 → 14.27.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/dist/commands/build.d.ts +3 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +22 -0
- package/dist/commands/dev.d.ts +3 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +10 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +5 -0
- package/dist/config/devServer.d.ts +4 -0
- package/dist/config/devServer.d.ts.map +1 -0
- package/dist/config/devServer.js +75 -0
- package/dist/config/entry.d.ts +4 -0
- package/dist/config/entry.d.ts.map +1 -0
- package/dist/config/entry.js +19 -0
- package/dist/config/federation.d.ts +15 -0
- package/dist/config/federation.d.ts.map +1 -0
- package/dist/config/federation.js +69 -0
- package/dist/config/getConfig.d.ts +9 -0
- package/dist/config/getConfig.d.ts.map +1 -0
- package/dist/config/getConfig.js +46 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +4 -0
- package/dist/config/module.d.ts +4 -0
- package/dist/config/module.d.ts.map +1 -0
- package/dist/config/module.js +20 -0
- package/dist/config/optimization.d.ts +4 -0
- package/dist/config/optimization.d.ts.map +1 -0
- package/dist/config/optimization.js +39 -0
- package/dist/config/output.d.ts +4 -0
- package/dist/config/output.d.ts.map +1 -0
- package/dist/config/output.js +34 -0
- package/dist/config/plugins.d.ts +4 -0
- package/dist/config/plugins.d.ts.map +1 -0
- package/dist/config/plugins.js +79 -0
- package/dist/config/resolveLoader.d.ts +4 -0
- package/dist/config/resolveLoader.d.ts.map +1 -0
- package/dist/config/resolveLoader.js +18 -0
- package/dist/{rules → config/rules}/fileRules.d.ts +5 -5
- package/dist/config/rules/fileRules.d.ts.map +1 -0
- package/dist/{rules → config/rules}/fileRules.js +4 -4
- package/dist/{rules → config/rules}/scriptRules.d.ts +3 -4
- package/dist/config/rules/scriptRules.d.ts.map +1 -0
- package/dist/{rules → config/rules}/scriptRules.js +4 -6
- package/dist/{rules → config/rules}/styleRules.d.ts +10 -23
- package/dist/config/rules/styleRules.d.ts.map +1 -0
- package/dist/config/rules/styleRules.js +38 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/utils/fs.d.ts +2 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +18 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/package.json +5 -4
- package/src/commands/build.ts +24 -0
- package/src/commands/dev.ts +7 -0
- package/src/commands/index.ts +2 -0
- package/src/config/devServer.ts +88 -0
- package/src/config/entry.ts +24 -0
- package/src/config/federation.ts +91 -0
- package/src/config/getConfig.ts +49 -0
- package/src/config/index.ts +1 -0
- package/src/config/module.ts +21 -0
- package/src/config/optimization.ts +45 -0
- package/src/config/output.ts +42 -0
- package/src/config/plugins.ts +95 -0
- package/src/config/resolveLoader.ts +19 -0
- package/src/{rules/fileRules.js → config/rules/fileRules.ts} +1 -5
- package/src/{rules/scriptRules.js → config/rules/scriptRules.ts} +1 -8
- package/src/config/rules/styleRules.ts +38 -0
- package/src/index.ts +10 -9
- package/src/utils/fs.ts +13 -0
- package/src/utils/index.ts +1 -0
- package/dist/config/configFactory.d.ts +0 -7
- package/dist/config/configFactory.d.ts.map +0 -1
- package/dist/config/configFactory.js +0 -51
- package/dist/config/devServers.d.ts +0 -35
- package/dist/config/devServers.d.ts.map +0 -1
- package/dist/config/devServers.js +0 -67
- package/dist/config/postcss.config.d.ts +0 -2
- package/dist/config/postcss.config.d.ts.map +0 -1
- package/dist/config/postcss.config.js +0 -8
- package/dist/config/utils.d.ts +0 -20
- package/dist/config/utils.d.ts.map +0 -1
- package/dist/config/utils.js +0 -77
- package/dist/config/webpack.common.d.ts +0 -68
- package/dist/config/webpack.common.d.ts.map +0 -1
- package/dist/config/webpack.common.js +0 -106
- package/dist/config/webpack.dev.d.ts +0 -68
- package/dist/config/webpack.dev.d.ts.map +0 -1
- package/dist/config/webpack.dev.js +0 -31
- package/dist/config/webpack.prod.d.ts +0 -68
- package/dist/config/webpack.prod.d.ts.map +0 -1
- package/dist/config/webpack.prod.js +0 -43
- package/dist/rules/fileRules.d.ts.map +0 -1
- package/dist/rules/scriptRules.d.ts.map +0 -1
- package/dist/rules/styleRules.d.ts.map +0 -1
- package/dist/rules/styleRules.js +0 -53
- package/public/cert/README.md +0 -17
- package/public/cert/localhost.crt +0 -25
- package/public/cert/localhost.key +0 -28
- package/src/config/configFactory.js +0 -56
- package/src/config/devServers.js +0 -73
- package/src/config/postcss.config.js +0 -8
- package/src/config/utils.js +0 -99
- package/src/config/webpack.common.js +0 -109
- package/src/config/webpack.dev.js +0 -32
- package/src/config/webpack.prod.js +0 -47
- package/src/rules/styleRules.js +0 -60
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export declare const appScriptRules: {
|
|
2
|
+
typescript: () => {
|
|
3
3
|
test: RegExp;
|
|
4
4
|
exclude: RegExp;
|
|
5
5
|
use: {
|
|
6
6
|
loader: string;
|
|
7
7
|
options: {
|
|
8
|
-
configFile: string;
|
|
9
8
|
projectReferences: boolean;
|
|
10
9
|
};
|
|
11
10
|
}[];
|
|
12
11
|
};
|
|
13
|
-
}
|
|
12
|
+
};
|
|
14
13
|
//# sourceMappingURL=scriptRules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scriptRules.d.ts","sourceRoot":"","sources":["../../../src/config/rules/scriptRules.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc;;;;;;;;;;;CAa1B,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appScriptRules = void 0;
|
|
4
|
+
exports.appScriptRules = {
|
|
3
5
|
typescript: () => ({
|
|
4
6
|
test: /\.ts$/i,
|
|
5
7
|
exclude: /node_modules/,
|
|
@@ -7,13 +9,9 @@ const appScriptRules = {
|
|
|
7
9
|
{
|
|
8
10
|
loader: 'ts-loader',
|
|
9
11
|
options: {
|
|
10
|
-
configFile: path.resolve(process.cwd(), './tsconfig.json'),
|
|
11
12
|
projectReferences: true,
|
|
12
13
|
},
|
|
13
14
|
},
|
|
14
15
|
],
|
|
15
16
|
}),
|
|
16
17
|
};
|
|
17
|
-
module.exports = {
|
|
18
|
-
appScriptRules,
|
|
19
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
1
|
+
export declare const appStyleRules: {
|
|
2
|
+
headCss: () => {
|
|
3
3
|
test: RegExp;
|
|
4
4
|
include: RegExp[];
|
|
5
5
|
use: (string | {
|
|
@@ -11,12 +11,14 @@ export namespace appStyleRules {
|
|
|
11
11
|
loader: string;
|
|
12
12
|
options: {
|
|
13
13
|
postcssOptions: {
|
|
14
|
-
|
|
14
|
+
plugins: (string | (string | {
|
|
15
|
+
browsers: string;
|
|
16
|
+
})[])[];
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
})[];
|
|
18
20
|
};
|
|
19
|
-
|
|
21
|
+
css: (useHash?: boolean) => {
|
|
20
22
|
test: RegExp;
|
|
21
23
|
exclude: RegExp[];
|
|
22
24
|
use: ({
|
|
@@ -28,27 +30,12 @@ export namespace appStyleRules {
|
|
|
28
30
|
loader: string;
|
|
29
31
|
options: {
|
|
30
32
|
postcssOptions: {
|
|
31
|
-
|
|
33
|
+
plugins: (string | (string | {
|
|
34
|
+
browsers: string;
|
|
35
|
+
})[])[];
|
|
32
36
|
};
|
|
33
37
|
};
|
|
34
38
|
})[];
|
|
35
39
|
};
|
|
36
|
-
|
|
37
|
-
test: RegExp;
|
|
38
|
-
exclude: RegExp[];
|
|
39
|
-
use: (string | {
|
|
40
|
-
loader: string;
|
|
41
|
-
options: {
|
|
42
|
-
importLoaders: number;
|
|
43
|
-
};
|
|
44
|
-
} | {
|
|
45
|
-
loader: string;
|
|
46
|
-
options: {
|
|
47
|
-
postcssOptions: {
|
|
48
|
-
config: string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
})[];
|
|
52
|
-
};
|
|
53
|
-
}
|
|
40
|
+
};
|
|
54
41
|
//# sourceMappingURL=styleRules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styleRules.d.ts","sourceRoot":"","sources":["../../../src/config/rules/styleRules.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWzB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appStyleRules = void 0;
|
|
4
|
+
const cssLoader = (importLoaders = 1, useHash = true) => ({
|
|
5
|
+
loader: 'css-loader',
|
|
6
|
+
options: {
|
|
7
|
+
importLoaders,
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
const postCSSLoader = () => ({
|
|
11
|
+
loader: 'postcss-loader',
|
|
12
|
+
options: {
|
|
13
|
+
postcssOptions: {
|
|
14
|
+
plugins: [
|
|
15
|
+
'postcss-import',
|
|
16
|
+
[
|
|
17
|
+
'postcss-preset-env',
|
|
18
|
+
{
|
|
19
|
+
browsers: 'last 2 versions',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
const headCssPatterns = [/main\.css$/i, /head\.css$/i, /index\.css$/i];
|
|
27
|
+
exports.appStyleRules = {
|
|
28
|
+
headCss: () => ({
|
|
29
|
+
test: /\.css$/i,
|
|
30
|
+
include: headCssPatterns,
|
|
31
|
+
use: ['style-loader', cssLoader(), postCSSLoader()],
|
|
32
|
+
}),
|
|
33
|
+
css: (useHash = true) => ({
|
|
34
|
+
test: /\.css$/i,
|
|
35
|
+
exclude: [...headCssPatterns],
|
|
36
|
+
use: [cssLoader(), postCSSLoader()],
|
|
37
|
+
}),
|
|
38
|
+
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;8BAKhC,YAAY;AAAvC,wBAuBE"}
|
package/dist/index.js
CHANGED
|
@@ -2,23 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const build_kit_1 = require("@genesislcap/build-kit");
|
|
5
|
+
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
6
|
+
const commands_1 = require("./commands");
|
|
7
|
+
const config_1 = require("./config");
|
|
5
8
|
exports.default = (ctx) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
6
9
|
const { dirs: { cwd }, cli: { isDev, isAnalyze, isBuild, options }, enable: { mft }, } = ctx;
|
|
7
10
|
if (mft) {
|
|
8
11
|
const mftCLI = yield (0, build_kit_1.resolveBin)('make-federated-types', '@pixability-ui/federated-types');
|
|
9
12
|
(0, build_kit_1.run)(cwd, `${mftCLI}`);
|
|
10
13
|
}
|
|
11
|
-
const webpack = yield (0, build_kit_1.resolveBin)('webpack');
|
|
12
14
|
if (isDev) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
(0,
|
|
15
|
+
const config = (0, config_1.getConfig)(ctx);
|
|
16
|
+
const compiler = (0, webpack_1.default)(config);
|
|
17
|
+
(0, commands_1.dev)(compiler, config);
|
|
16
18
|
}
|
|
17
|
-
else if (isAnalyze) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(0, build_kit_1.run)(cwd, `${webpack}`);
|
|
19
|
+
else if (isBuild || isAnalyze) {
|
|
20
|
+
const config = (0, config_1.getConfig)(ctx);
|
|
21
|
+
const compiler = (0, webpack_1.default)(config);
|
|
22
|
+
yield (0, commands_1.build)(compiler);
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
25
|
throw new Error(`Unrecognised command: ${JSON.stringify(options)}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../../src/utils/fs.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,2BASpB,CAAC"}
|
package/dist/utils/fs.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readFile = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const readFile = (filePath) => {
|
|
7
|
+
if (!filePath)
|
|
8
|
+
return '';
|
|
9
|
+
const resolvedPath = (0, node_path_1.resolve)(process.cwd(), filePath);
|
|
10
|
+
try {
|
|
11
|
+
return (0, node_fs_1.readFileSync)(resolvedPath, 'utf8');
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
console.error(e);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
exports.readFile = readFile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/webpack-builder",
|
|
3
3
|
"description": "Webpack builder",
|
|
4
|
-
"version": "14.
|
|
4
|
+
"version": "14.27.0",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"dev": "tsc -b ./tsconfig.json -w"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@genesislcap/build-kit": "14.
|
|
15
|
+
"@genesislcap/build-kit": "^14.27.0",
|
|
16
16
|
"@module-federation/dashboard-plugin": "2.6.5",
|
|
17
17
|
"@pixability-ui/federated-types": "^0.2.0",
|
|
18
18
|
"camel-case": "^4.1.2",
|
|
@@ -34,14 +34,15 @@
|
|
|
34
34
|
"typescript": "^4.5.5",
|
|
35
35
|
"webpack": "^5.84.1",
|
|
36
36
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
37
|
-
"webpack-cli": "^4.5.0",
|
|
38
37
|
"webpack-dev-server": "^4.0.0-beta.3",
|
|
39
38
|
"webpack-merge": "^5.7.3",
|
|
40
39
|
"webpack-pwa-manifest": "^4.3.0",
|
|
40
|
+
"webpackbar": "^5.0.2",
|
|
41
41
|
"workbox-webpack-plugin": "^6.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"copyfiles": "^2.4.1",
|
|
45
|
+
"pkg-types": "^1.0.2",
|
|
45
46
|
"rimraf": "^5.0.0"
|
|
46
47
|
},
|
|
47
48
|
"repository": {
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "1a9014d142a55fa36af122935e0a6c111810fe8d"
|
|
56
57
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import webpack from 'webpack';
|
|
2
|
+
import type { Compiler } from 'webpack';
|
|
3
|
+
|
|
4
|
+
export const build = async (compiler: Compiler) => {
|
|
5
|
+
const stats = await new Promise<webpack.Stats>((success, error) => {
|
|
6
|
+
compiler.run((err, result) => (err ? error(err) : success(result!)));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
if (stats.hasErrors()) {
|
|
10
|
+
const error = new Error('Build error');
|
|
11
|
+
error.stack = stats.toString('errors-only');
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
process.stdout.write(
|
|
16
|
+
stats.toString({
|
|
17
|
+
colors: true,
|
|
18
|
+
modules: false,
|
|
19
|
+
children: false,
|
|
20
|
+
chunks: false,
|
|
21
|
+
chunkModules: false,
|
|
22
|
+
}) + '\n\n'
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Compiler, Configuration } from 'webpack';
|
|
2
|
+
import WebpackDevServer from 'webpack-dev-server';
|
|
3
|
+
|
|
4
|
+
export const dev = async (compiler: Compiler, config: Configuration) => {
|
|
5
|
+
const server = new WebpackDevServer(config.devServer, compiler);
|
|
6
|
+
await server.start();
|
|
7
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
4
|
+
import portfinderSync from 'portfinder-sync';
|
|
5
|
+
import type { Configuration } from 'webpack';
|
|
6
|
+
|
|
7
|
+
const getPort = (packageJson): number =>
|
|
8
|
+
portfinderSync.getPort(packageJson.config?.PORT || process.env.PORT || 9000);
|
|
9
|
+
|
|
10
|
+
const getServer = (isHTTPS = false) => {
|
|
11
|
+
if (isHTTPS) {
|
|
12
|
+
const certDir = resolve(__dirname, '../../cert/');
|
|
13
|
+
const cert = resolve(certDir, 'localhost.crt');
|
|
14
|
+
const key = resolve(certDir, 'localhost.key');
|
|
15
|
+
|
|
16
|
+
if (existsSync(cert) && existsSync(key)) {
|
|
17
|
+
return {
|
|
18
|
+
type: 'https',
|
|
19
|
+
options: {
|
|
20
|
+
cert: readFileSync(cert),
|
|
21
|
+
key: readFileSync(key),
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
} else {
|
|
25
|
+
console.warn(`Could not load certificates from ${certDir}. Falling back to HTTP.`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
type: 'http',
|
|
31
|
+
options: {},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const convertWsEndpointToHTTP = (endpoint = '', socketExt) =>
|
|
36
|
+
endpoint.replace(/^ws(s)?:\/\//, 'http$1://').replace(`/${socketExt}`, '');
|
|
37
|
+
|
|
38
|
+
export const devServer = (ctx: BuildContext): Configuration['devServer'] => {
|
|
39
|
+
const {
|
|
40
|
+
cli: {
|
|
41
|
+
isDev,
|
|
42
|
+
options: { open, https },
|
|
43
|
+
},
|
|
44
|
+
dirs: { cwd },
|
|
45
|
+
env: { isCI },
|
|
46
|
+
pkg,
|
|
47
|
+
} = ctx;
|
|
48
|
+
|
|
49
|
+
if (!isDev) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const port = getPort(pkg);
|
|
53
|
+
const socketExt = process.env.SOCKET_EXT || 'gwf';
|
|
54
|
+
const target = convertWsEndpointToHTTP(process.env.API_HOST, socketExt);
|
|
55
|
+
return {
|
|
56
|
+
open: open && !isCI,
|
|
57
|
+
historyApiFallback: true,
|
|
58
|
+
allowedHosts: 'all',
|
|
59
|
+
host: 'localhost',
|
|
60
|
+
port,
|
|
61
|
+
server: getServer(https),
|
|
62
|
+
client: {
|
|
63
|
+
overlay: {
|
|
64
|
+
runtimeErrors: false,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
proxy: [
|
|
68
|
+
{
|
|
69
|
+
context: [`/${socketExt}/**`, '/sso/**'],
|
|
70
|
+
target,
|
|
71
|
+
secure: false,
|
|
72
|
+
changeOrigin: true,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
headers: {
|
|
76
|
+
'Access-Control-Allow-Origin': '*',
|
|
77
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
78
|
+
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
|
|
79
|
+
},
|
|
80
|
+
static: [
|
|
81
|
+
{
|
|
82
|
+
directory: resolve(cwd, './public'),
|
|
83
|
+
publicPath: '/',
|
|
84
|
+
watch: true,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
3
|
+
import type { Configuration } from 'webpack';
|
|
4
|
+
import { resolveFederatedIndex, federatedIndexExists } from './federation';
|
|
5
|
+
|
|
6
|
+
export const entry = (ctx: BuildContext): Configuration['entry'] => {
|
|
7
|
+
const {
|
|
8
|
+
dirs: { cwd },
|
|
9
|
+
config: { serviceWorker },
|
|
10
|
+
} = ctx;
|
|
11
|
+
|
|
12
|
+
const main = federatedIndexExists()
|
|
13
|
+
? resolveFederatedIndex()
|
|
14
|
+
: resolve(cwd, './src/' + 'index.ts');
|
|
15
|
+
|
|
16
|
+
if (serviceWorker?.registration) {
|
|
17
|
+
return {
|
|
18
|
+
main,
|
|
19
|
+
swRegistration: resolve(cwd, './src/' + serviceWorker.registration),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return main;
|
|
24
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import DashboardPlugin from '@module-federation/dashboard-plugin';
|
|
4
|
+
import { camelCase } from 'camel-case';
|
|
5
|
+
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
6
|
+
import { PackageJson } from 'pkg-types';
|
|
7
|
+
import { container } from 'webpack';
|
|
8
|
+
|
|
9
|
+
const { ModuleFederationPlugin } = container;
|
|
10
|
+
type ModuleFederationPluginOptions = ConstructorParameters<
|
|
11
|
+
typeof container.ModuleFederationPlugin
|
|
12
|
+
>[0]; // eslint-disable-line @typescript-eslint/no-magic-numbers
|
|
13
|
+
|
|
14
|
+
const remoteEntryFilename = 'remoteEntry.js';
|
|
15
|
+
|
|
16
|
+
export const getFederatedPkgName = (pkgName) => {
|
|
17
|
+
try {
|
|
18
|
+
return camelCase(pkgName.split('/').pop());
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return pkgName;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const federatedIndex = './src/index.federated.ts';
|
|
25
|
+
|
|
26
|
+
export const resolveFederatedIndex = () => resolve(process.cwd(), federatedIndex);
|
|
27
|
+
|
|
28
|
+
export const federatedIndexExists = () => {
|
|
29
|
+
const federatedIndexPath = resolveFederatedIndex();
|
|
30
|
+
return existsSync(federatedIndexPath);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* TODO: Add prod version logic
|
|
35
|
+
*/
|
|
36
|
+
export const getRemoteEntryUrl = (port, host = 'localhost') =>
|
|
37
|
+
`http://${host}:${port}/${remoteEntryFilename}`;
|
|
38
|
+
|
|
39
|
+
export const getRemoteEntry = (name, port, host = 'localhost') =>
|
|
40
|
+
`${name}@${getRemoteEntryUrl(port, host)}`;
|
|
41
|
+
|
|
42
|
+
export const resolveFederationOptions = (
|
|
43
|
+
options: ModuleFederationPluginOptions = {},
|
|
44
|
+
pkg: PackageJson
|
|
45
|
+
): ModuleFederationPluginOptions => {
|
|
46
|
+
const { name, exposes: mfExposes = {}, remotes: mfRemotes = {}, shared: mfShared = {} } = options;
|
|
47
|
+
|
|
48
|
+
const exposes = {
|
|
49
|
+
'./index': federatedIndex,
|
|
50
|
+
...mfExposes,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const shared = {
|
|
54
|
+
...pkg.dependencies,
|
|
55
|
+
...mfShared,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
name: name || getFederatedPkgName(pkg.name),
|
|
60
|
+
filename: remoteEntryFilename,
|
|
61
|
+
remotes: mfRemotes,
|
|
62
|
+
exposes,
|
|
63
|
+
shared,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const getFederationPlugins = (
|
|
68
|
+
federatedIndexPresent: boolean,
|
|
69
|
+
rootElement: string,
|
|
70
|
+
options: ModuleFederationPluginOptions,
|
|
71
|
+
pkg: PackageJson
|
|
72
|
+
) =>
|
|
73
|
+
federatedIndexPresent
|
|
74
|
+
? [
|
|
75
|
+
new HtmlWebpackPlugin({
|
|
76
|
+
title: `${pkg.description} (Federated)`,
|
|
77
|
+
template: resolve(__dirname, '../../public/info.ejs'),
|
|
78
|
+
filename: rootElement ? 'info.html' : 'index.html',
|
|
79
|
+
inject: false,
|
|
80
|
+
// Passing arbitrary data to the template for display
|
|
81
|
+
moduleFederationDetails: JSON.stringify(options, undefined, 2),
|
|
82
|
+
minify: false,
|
|
83
|
+
}),
|
|
84
|
+
new ModuleFederationPlugin(options),
|
|
85
|
+
process.env.FEDERATION_DASHABORD_URL &&
|
|
86
|
+
new DashboardPlugin({
|
|
87
|
+
dashboardURL: `${process.env.FEDERATION_DASHABORD_URL}/api/update`,
|
|
88
|
+
publishVersion: pkg.version,
|
|
89
|
+
}),
|
|
90
|
+
]
|
|
91
|
+
: [];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
+
import type { Configuration } from 'webpack';
|
|
3
|
+
import { devServer } from './devServer';
|
|
4
|
+
import { entry } from './entry';
|
|
5
|
+
import { moduleConfig } from './module';
|
|
6
|
+
import { optimization } from './optimization';
|
|
7
|
+
import { output } from './output';
|
|
8
|
+
import { plugins } from './plugins';
|
|
9
|
+
import { resolveLoader } from './resolveLoader';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param ctx Build context
|
|
14
|
+
* @returns Webpack config
|
|
15
|
+
*/
|
|
16
|
+
export const getConfig = (ctx: BuildContext): Configuration => {
|
|
17
|
+
const {
|
|
18
|
+
cli: { isDev },
|
|
19
|
+
config: { webpack },
|
|
20
|
+
} = ctx;
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
entry: entry(ctx),
|
|
24
|
+
mode: isDev ? 'development' : 'production',
|
|
25
|
+
// Be aware of CSP if changing this to eval: https://github.com/symfony/webpack-encore/issues/695
|
|
26
|
+
devtool: isDev ? 'inline-source-map' : 'source-map',
|
|
27
|
+
devServer: devServer(ctx),
|
|
28
|
+
optimization: optimization(ctx),
|
|
29
|
+
plugins: plugins(ctx),
|
|
30
|
+
output: output(ctx),
|
|
31
|
+
resolve: {
|
|
32
|
+
extensions: ['.ts', '.js'],
|
|
33
|
+
modules: ['node_modules'],
|
|
34
|
+
},
|
|
35
|
+
resolveLoader: resolveLoader(ctx),
|
|
36
|
+
module: moduleConfig(ctx),
|
|
37
|
+
experiments: {
|
|
38
|
+
topLevelAwait: true,
|
|
39
|
+
lazyCompilation: false,
|
|
40
|
+
},
|
|
41
|
+
performance: {
|
|
42
|
+
hints: false,
|
|
43
|
+
maxEntrypointSize: 512000,
|
|
44
|
+
maxAssetSize: 512000,
|
|
45
|
+
},
|
|
46
|
+
target: webpack?.target,
|
|
47
|
+
node: webpack?.node,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getConfig';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
+
import type { Configuration } from 'webpack';
|
|
3
|
+
import { appFileRules } from './rules/fileRules';
|
|
4
|
+
import { appScriptRules } from './rules/scriptRules';
|
|
5
|
+
import { appStyleRules } from './rules/styleRules';
|
|
6
|
+
|
|
7
|
+
// module is reserved keyword in CommonJS
|
|
8
|
+
export const moduleConfig = (ctx: BuildContext): Configuration['module'] => ({
|
|
9
|
+
rules: [
|
|
10
|
+
appScriptRules.typescript(),
|
|
11
|
+
|
|
12
|
+
// Files
|
|
13
|
+
appFileRules.fonts(),
|
|
14
|
+
appFileRules.html(),
|
|
15
|
+
appFileRules.images(),
|
|
16
|
+
|
|
17
|
+
// Styles
|
|
18
|
+
appStyleRules.headCss(),
|
|
19
|
+
appStyleRules.css(),
|
|
20
|
+
],
|
|
21
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
2
|
+
import TerserPlugin from 'terser-webpack-plugin';
|
|
3
|
+
import type { Configuration } from 'webpack';
|
|
4
|
+
|
|
5
|
+
const vendorCacheGroup = {
|
|
6
|
+
vendor: {
|
|
7
|
+
test: /[\\/]node_modules[\\/]/,
|
|
8
|
+
name: (module) => {
|
|
9
|
+
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
|
|
10
|
+
// npm package names are URL-safe, but some servers don't like @ symbols
|
|
11
|
+
return `npm.${packageName.replace('@', '')}`;
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const optimization = (ctx: BuildContext): Configuration['optimization'] => {
|
|
17
|
+
const {
|
|
18
|
+
config: { webpack },
|
|
19
|
+
cli: { isDev },
|
|
20
|
+
} = ctx;
|
|
21
|
+
|
|
22
|
+
// user-supplied custom config
|
|
23
|
+
if (typeof webpack?.optimization === 'function') {
|
|
24
|
+
return webpack.optimization({ isDev });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// defaults
|
|
28
|
+
return isDev
|
|
29
|
+
? {
|
|
30
|
+
usedExports: false,
|
|
31
|
+
minimize: false,
|
|
32
|
+
}
|
|
33
|
+
: {
|
|
34
|
+
usedExports: true,
|
|
35
|
+
minimize: true,
|
|
36
|
+
minimizer: [new TerserPlugin()],
|
|
37
|
+
splitChunks: {
|
|
38
|
+
chunks: 'all',
|
|
39
|
+
maxInitialRequests: 100,
|
|
40
|
+
cacheGroups: {
|
|
41
|
+
...vendorCacheGroup,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import type { BuildContext } from '@genesislcap/build-kit';
|
|
3
|
+
import type { WebpackFilenames } from '@genesislcap/build-kit';
|
|
4
|
+
import type { Configuration } from 'webpack';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Switching the '/' instead of 'auto', as webpack and perhaps the html-webpack-plugin seem to get confused over
|
|
8
|
+
* mime types, and this can block deep linking. Reading through the 'Practical Module Federation' guide, we may need
|
|
9
|
+
* to revisit this, dev v prod, resolving remotes.
|
|
10
|
+
*/
|
|
11
|
+
const publicPath = typeof process.env.PUBLIC_PATH !== 'undefined' ? process.env.PUBLIC_PATH : '/';
|
|
12
|
+
|
|
13
|
+
const defaultGetters: WebpackFilenames = {
|
|
14
|
+
file: ({ isDev }) => (isDev ? '[name].js' : '[name].[contenthash].js'),
|
|
15
|
+
chunk: ({ isDev }) => (isDev ? '[name].[id].js' : '[name].[id].[contenthash].js'),
|
|
16
|
+
sourceMap: ({ isDev }) => (isDev ? '[name].js.map' : '[name].[contenthash].js.map'),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const filenameGetters = (config: WebpackFilenames = {}): WebpackFilenames => ({
|
|
20
|
+
file: config.file || defaultGetters.file,
|
|
21
|
+
chunk: config.chunk || defaultGetters.chunk,
|
|
22
|
+
sourceMap: config.sourceMap || defaultGetters.sourceMap,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const output = (ctx: BuildContext): Configuration['output'] => {
|
|
26
|
+
const {
|
|
27
|
+
cli: { isDev },
|
|
28
|
+
dirs: { cwd },
|
|
29
|
+
config: { webpack },
|
|
30
|
+
} = ctx;
|
|
31
|
+
|
|
32
|
+
const getters = filenameGetters(webpack?.filenames);
|
|
33
|
+
return {
|
|
34
|
+
strictModuleErrorHandling: true,
|
|
35
|
+
strictModuleExceptionHandling: true,
|
|
36
|
+
path: resolve(cwd, './dist'),
|
|
37
|
+
publicPath,
|
|
38
|
+
filename: getters.file({ isDev }),
|
|
39
|
+
chunkFilename: getters.chunk({ isDev }),
|
|
40
|
+
sourceMapFilename: getters.sourceMap({ isDev }),
|
|
41
|
+
};
|
|
42
|
+
};
|