Skip to content

Commit 3d45303

Browse files
author
HienTM
committed
build: setup
1 parent 5af2376 commit 3d45303

15 files changed

+6183
-185
lines changed

.eslintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{ "extends": "react-ts" }
1+
{
2+
"extends": [
3+
"react-ts"
4+
]
5+
}

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict=true

.prettierrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
{ "arrowParens": "avoid", "singleQuote": true, "trailingComma": "all" }
1+
{
2+
"trailingComma": "all",
3+
"singleQuote": true
4+
}

.release-it.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"git": {
3+
"commitMessage": "chore(release): release ${version}"
4+
},
5+
"github": {
6+
"release": true
7+
},
8+
"npm": {
9+
"publish": true
10+
}
11+
}

.size-limit.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"path": "dist/index.es.js",
4+
"limit": "2 kb"
5+
}
6+
]

.vscode/settings.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"editor.tabSize": 2,
6+
"eslint.enable": true,
7+
"sonarlint.connectedMode.project": {
8+
"projectKey": "cb-react-micro-frontend"
9+
},
210
"javascript.preferences.quoteStyle": "single",
311
"typescript.preferences.quoteStyle": "single",
412
"javascript.updateImportsOnFileMove.enabled": "always",
513
"typescript.updateImportsOnFileMove.enabled": "always",
6-
"eslint.enable": true,
7-
"editor.codeActionsOnSave": {
8-
"source.fixAll.eslint": true
9-
},
1014
"eslint.validate": [
1115
"javascript",
1216
"javascriptreact",
1317
"typescript",
1418
"typescriptreact"
1519
],
16-
"editor.tabSize": 2,
1720
"cSpell.words": [
1821
"entrypoints"
1922
]

commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};

dist/index.es.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@ const getRegistries = () => {
1212
return win._mfRegistries;
1313
};
1414

15+
var f="_mfInfo";
16+
1517
/* eslint-disable no-underscore-dangle */
1618
const win = window;
17-
const mfInfoKey = '_mfInfo';
18-
const isLoadedAsMicroFrontend = (name) => { var _a; return name === ((_a = win[mfInfoKey]) === null || _a === void 0 ? void 0 : _a.name); };
19+
const isLoadedAsMicroFrontend = (name) => { var _a; return name === ((_a = win[f]) === null || _a === void 0 ? void 0 : _a.name); };
1920
const removeMicroFrontendInfo = (name) => {
2021
var _a;
21-
if (!name || ((_a = win[mfInfoKey]) === null || _a === void 0 ? void 0 : _a.name) === name) {
22-
win[mfInfoKey] = undefined;
23-
document.cookie = `${mfInfoKey}=; Max-Age=-99999999;`;
22+
if (!name || ((_a = win[f]) === null || _a === void 0 ? void 0 : _a.name) === name) {
23+
win[f] = undefined;
24+
document.cookie = `${f}=; Max-Age=-99999999;`;
2425
}
2526
};
2627
const setMicroFrontendInfo = (name, host) => {
2728
const info = { host, name };
28-
win[mfInfoKey] = info;
29+
win[f] = info;
2930
const expires = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000);
30-
document.cookie = `${mfInfoKey}=${JSON.stringify(info)}; expires=${expires.toUTCString()}; path=/`;
31+
document.cookie = `${f}=${JSON.stringify(info)}; expires=${expires.toUTCString()}; path=/`;
3132
};
3233

3334
const renderMicroFrontend = (name, history, microFrontendPath) => { var _a; return (_a = getRegistries().get(name)) === null || _a === void 0 ? void 0 : _a.render(history, microFrontendPath); };
@@ -81,11 +82,11 @@ const fetchManifest = async (host) => {
8182
const res = await fetch(resolveUrl(host, '/asset-manifest.json'));
8283
return res.json();
8384
};
84-
const fetchScripts = (manifest, host, scriptId) => new Promise(resolve => {
85+
const fetchScripts = (manifest, host, scriptId) => new Promise((resolve) => {
8586
let count = 0;
8687
const mainJsUrl = resolveUrl(host, manifest.files['main.js']);
87-
const scriptEntries = manifest.entrypoints.filter(entry => entry.endsWith('.js'));
88-
scriptEntries.forEach(entry => {
88+
const scriptEntries = manifest.entrypoints.filter((entry) => entry.endsWith('.js'));
89+
scriptEntries.forEach((entry) => {
8990
const script = document.createElement('script');
9091
const entryUrl = resolveUrl(host, entry);
9192
script.src = entryUrl;
@@ -123,7 +124,7 @@ const MicroFrontendRoute = memo(MicroFrontendRouteComponent);
123124
MicroFrontendRoute.displayName = 'MicroFrontendRoute';
124125

125126
const MicroFrontendRoutesComponent = ({ fallback, routeProps, }) => (React.createElement(Switch, null,
126-
React.createElement(Suspense, { fallback: fallback }, routeProps.map(props => (React.createElement(MicroFrontendRoute, Object.assign({}, props, { key: props.microFrontendName })))))));
127+
React.createElement(Suspense, { fallback: fallback }, routeProps.map((props) => (React.createElement(MicroFrontendRoute, Object.assign({}, props, { key: props.microFrontendName })))))));
127128
const MicroFrontendRoutes = memo(MicroFrontendRoutesComponent);
128129
MicroFrontendRoutes.displayName = 'MicroFrontendRoutes';
129130

package.json

+54-14
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,83 @@
11
{
22
"name": "cb-react-micro-frontend",
3-
"version": "0.0.19",
4-
"description": "React micro-frontend core",
5-
"repository": "https://github.com/ICodeMyOwnLife/cb-react-micro-frontend.git",
3+
"version": "0.0.22",
4+
"description": "Reusable functions for setting up micro-frontends and containers",
65
"author": "Hien CB",
6+
"repository": "https://github.com/ICodeMyOwnLife/cb-react-micro-frontend.git",
77
"license": "MIT",
8+
"private": false,
89
"source": "src/index.ts",
910
"module": "dist/index.es.js",
1011
"types": "dist/index.d.ts",
1112
"scripts": {
12-
"build": "rollup -c -w",
13-
"build:config": "tsc rollup.config.ts --target es2017 --module es2015 --moduleResolution node --skipLibCheck --allowSyntheticDefaultImports -w",
14-
"prebuild": "rm -rf dist",
13+
"build": "rollup -c",
14+
"build:config": "tsc rollup.config.ts --target es2017 --module es2015 --moduleResolution node --skipLibCheck --allowSyntheticDefaultImports",
15+
"commit": "git-cz",
16+
"dev": "microbundle watch --jsx React.createElement",
17+
"lint": "eslint 'src/**/*.{ts,tsx}'",
18+
"lint:fix": "yarn lint --fix",
19+
"prebuild": "del dist",
20+
"release": "release-it",
21+
"size": "yarn build && size-limit",
1522
"type-check": "tsc --noEmit"
1623
},
24+
"dependencies": {
25+
"cb-react-micro-frontend-core": "^0.0.3"
26+
},
1727
"devDependencies": {
28+
"@commitlint/cli": "^8.3.5",
29+
"@commitlint/config-conventional": "^8.3.4",
30+
"@rollup/plugin-node-resolve": "^7.1.3",
31+
"@size-limit/preset-small-lib": "^4.3.1",
1832
"@types/history": "^4.7.5",
19-
"@types/node": "^13.13.2",
33+
"@types/node": "^13.13.4",
2034
"@types/react": "^16.9.34",
21-
"@types/react-dom": "^16.9.6",
22-
"@types/react-router": "^5.1.5",
35+
"@types/react-dom": "^16.9.7",
36+
"@types/react-router": "^5.1.7",
37+
"commitizen": "^4.0.3",
38+
"cz-conventional-changelog": "^3.1.0",
39+
"del-cli": "^3.0.0",
2340
"eslint": "^6.8.0",
2441
"eslint-config-react-ts": "^2.1.0",
2542
"history": "^4.10.1",
43+
"husky": "^4.2.3",
44+
"lint-staged": "^10.0.8",
2645
"react": "^16.13.1",
2746
"react-dom": "^16.13.1",
2847
"react-router": "^5.1.2",
29-
"rollup": "^2.7.2",
48+
"release-it": "^13.0.2",
49+
"rollup": "^2.7.3",
3050
"rollup-plugin-cleanup": "^3.1.1",
3151
"rollup-plugin-typescript2": "^0.27.0",
52+
"size-limit": "^4.3.1",
3253
"typescript": "^3.8.3"
3354
},
3455
"peerDependencies": {
3556
"history": "^4.10.1",
36-
"react": "^16.13.1",
37-
"react-dom": "^16.13.1",
57+
"react": "> 16.8.0",
58+
"react-dom": "> 16.8.0",
3859
"react-router": "^5.1.2"
3960
},
40-
"dependencies": {
41-
"cb-react-micro-frontend-core": "^0.0.3"
61+
"config": {
62+
"commitizen": {
63+
"path": "./node_modules/cz-conventional-changelog"
64+
}
65+
},
66+
"husky": {
67+
"hooks": {
68+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
69+
"pre-commit": "yarn type-check && yarn lint-staged && yarn size"
70+
}
71+
},
72+
"lint-staged": {
73+
"{*.{json,md}}": [
74+
"prettier --write"
75+
],
76+
"*.{js,jsx,ts,tsx}": [
77+
"yarn lint:fix"
78+
]
79+
},
80+
"engines": {
81+
"node": ">=12.0.0"
4282
}
4383
}

rollup.config.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import typescript from 'rollup-plugin-typescript2';
2+
import resolve from '@rollup/plugin-node-resolve';
23
import cleanup from 'rollup-plugin-cleanup';
4+
35
const input = 'src/index.ts';
4-
const external = id => !!id.match(/^(react|react-dom|history|react-router|react-router-dom)/);
6+
const external = (id) =>
7+
!!id.match(/^(react|react-dom|history|react-router|react-router-dom)/);
58
const tsconfig = './tsconfig.json';
69
const plugins = [
7-
typescript({ tsconfig, clean: true }),
8-
cleanup({ comments: 'none' }),
10+
typescript({ tsconfig, clean: true }),
11+
resolve(),
12+
cleanup({ comments: 'none' }),
913
];
1014
const watch = { include: ['src/**'] };
1115
const esOptions = {
12-
input,
13-
external,
14-
output: {
15-
file: 'dist/index.es.js',
16-
format: 'es',
17-
},
18-
plugins,
19-
watch,
16+
input,
17+
external,
18+
output: {
19+
file: 'dist/index.es.js',
20+
format: 'es',
21+
},
22+
plugins,
23+
watch,
2024
};
2125
const options = [esOptions];
2226
export default options;

rollup.config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import {
77
WatcherOptions,
88
} from 'rollup';
99
import typescript from 'rollup-plugin-typescript2';
10+
import resolve from '@rollup/plugin-node-resolve';
1011
import cleanup from 'rollup-plugin-cleanup';
1112

1213
const input: InputOption = 'src/index.ts';
13-
const external: ExternalOption = id =>
14+
const external: ExternalOption = (id) =>
1415
!!id.match(/^(react|react-dom|history|react-router|react-router-dom)/);
1516
const tsconfig = './tsconfig.json';
1617
const plugins: Plugin[] = [
1718
typescript({ tsconfig, clean: true }),
19+
resolve(),
1820
cleanup({ comments: 'none' }),
1921
];
2022
const watch: WatcherOptions = { include: ['src/**'] };

sonar-project.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sonar.projectKey=cb-react-micro-frontend

src/MicroFrontendRoutes/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const MicroFrontendRoutesComponent: FC<MicroFrontendRoutesProps> = ({
99
}) => (
1010
<Switch>
1111
<Suspense fallback={fallback}>
12-
{routeProps.map(props => (
12+
{routeProps.map((props) => (
1313
<MicroFrontendRoute {...props} key={props.microFrontendName} />
1414
))}
1515
</Suspense>

src/lazyLoadMicroFrontend.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const fetchManifest = async (host: string) => {
1414
};
1515

1616
const fetchScripts = (manifest: Manifest, host: string, scriptId: string) =>
17-
new Promise<void>(resolve => {
17+
new Promise<void>((resolve) => {
1818
let count = 0;
1919
const mainJsUrl = resolveUrl(host, manifest.files['main.js']);
20-
const scriptEntries = manifest.entrypoints.filter(entry =>
20+
const scriptEntries = manifest.entrypoints.filter((entry) =>
2121
entry.endsWith('.js'),
2222
);
23-
scriptEntries.forEach(entry => {
23+
scriptEntries.forEach((entry) => {
2424
const script = document.createElement('script');
2525
const entryUrl = resolveUrl(host, entry);
2626
script.src = entryUrl;

0 commit comments

Comments
 (0)