Skip to content

Create Rslib executor for Nx #3876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: rslib-executor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/rslib-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@module-federation/rsbuild-plugin": "workspace:*",
"@module-federation/storybook-addon": "workspace:*",
"@rsbuild/plugin-react": "^1.0.6",
"@rslib/core": "0.2.0",
"@rslib/core": "0.10.4",
"@types/react": "^18.3.11",
"http-server": "^14.1.1",
"react": "^18.3.1",
Expand Down
54 changes: 48 additions & 6 deletions apps/rslib-module/project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
{
"name": "rslib-module",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/rslib-module/src",
"sourceRoot": "apps/rslib-module/src",
"projectType": "library",
"tags": ["type:app"],
"targets": {
"build": {
"executor": "nx:run-commands",
"executor": "../../tools/rslib-plugin:build",
"outputs": ["{projectRoot}/dist"],
"options": {
"commands": ["npm run build --prefix apps/rslib-module"]
"configFile": "rslib.config.ts",
"mode": "production"
},
"configurations": {
"development": {
"mode": "development"
},
"watch": {
"watch": true
}
}
},
"dev": {
"executor": "../../tools/rslib-plugin:dev",
"options": {
"configFile": "rslib.config.ts",
"mode": "mf-dev",
"port": 3001,
"open": false
},
"dependsOn": [
{
"target": "build",
"dependencies": true
}
]
},
"serve": {
"executor": "nx:run-commands",
"options": {
Expand All @@ -23,10 +48,11 @@
}
]
},
"dev": {
"executor": "nx:run-commands",
"build-watch": {
"executor": "../../tools/rslib-plugin:dev",
"options": {
"commands": ["npm run dev --prefix apps/rslib-module"]
"configFile": "rslib.config.ts",
"mode": "watch"
},
"dependsOn": [
{
Expand All @@ -35,6 +61,22 @@
}
]
},
"test": {
"executor": "../../tools/rslib-plugin:build",
"options": {
"configFile": "rslib.config.ts",
"mode": "development",
"verbose": true
}
},
"test:watch": {
"executor": "../../tools/rslib-plugin:build",
"options": {
"configFile": "rslib.config.ts",
"mode": "development",
"watch": true
}
},
"storybook": {
"executor": "nx:run-commands",
"options": {
Expand Down
22 changes: 14 additions & 8 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"cache": true
},
"lint": {
"inputs": ["default", "{workspaceRoot}/.eslintrc.json"],
"inputs": [
"default",
"{workspaceRoot}/.eslintrc.json",
"{workspaceRoot}/.eslintignore",
"{workspaceRoot}/eslint.config.js"
],
"cache": true
},
"test": {
Expand Down Expand Up @@ -63,17 +68,15 @@
"default": ["{projectRoot}/**/*", "sharedGlobals"],
"production": [
"default",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
"!{projectRoot}/tsconfig.spec.json",
"!{projectRoot}/jest.config.[jt]s",
"!{projectRoot}/vitest.config.[jt]s",
"!{projectRoot}/.storybook/**/*",
"!{projectRoot}/**/*.stories.@(js|jsx|ts|tsx|mdx)",
"!{projectRoot}/src/test-setup.[jt]s",
"!{projectRoot}/tsconfig.storybook.json"
"!{projectRoot}/test-setup.[jt]s",
"!{projectRoot}/.eslintrc.json",
"!{projectRoot}/eslint.config.js"
],
"sharedGlobals": ["{workspaceRoot}/babel.config.json"]
"sharedGlobals": []
},
"workspaceLayout": {
"appsDir": "apps",
Expand Down Expand Up @@ -115,5 +118,8 @@
},
"useInferencePlugins": false,
"defaultBase": "main",
"nxCloudAccessToken": "NTVlZTRhOWItMGRjYy00YmJjLTllNzAtNDFkNzRhNzdjZDkwfHJlYWQtd3JpdGU="
"nxCloudAccessToken": "NTVlZTRhOWItMGRjYy00YmJjLTllNzAtNDFkNzRhNzdjZDkwfHJlYWQtd3JpdGU=",
"cli": {
"tui": false
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"@pmmmwh/react-refresh-webpack-plugin": "0.5.15",
"@rollup/plugin-alias": "5.1.1",
"@rollup/plugin-replace": "6.0.1",
"@rslib/core": "^0.10.4",
"@rspack/core": "1.3.9",
"@rspack/dev-server": "1.1.1",
"@semantic-release/changelog": "^6.0.3",
Expand Down
1 change: 1 addition & 0 deletions packages/bridge/vue3-bridge/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"src/remoteApp.tsx",
"src/create.ts"
],
"exclude": ["../../runtime-core/dist/**/*"],
"references": [{ "path": "./tsconfig.node.json" }]
}
3 changes: 2 additions & 1 deletion packages/chrome-devtools/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"types": ["chrome"]
},
"include": ["src", "shared", "modern.config.ts"]
"include": ["src", "shared", "modern.config.ts"],
"exclude": ["../runtime-core/dist/**/*"]
}
3 changes: 2 additions & 1 deletion packages/chrome-devtools/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "./tsconfig.base.json",
"include": ["src", "stories"]
"include": ["src", "stories"],
"exclude": ["../runtime-core/dist/**/*"]
}
4 changes: 3 additions & 1 deletion packages/enhanced/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"src/**/*.spec.ts",
"src/**/*.test.ts",
"dist/**",
"node_modules/**"
"node_modules/**",
"../runtime-core/src/**",
"../runtime-core/global.d.ts"
]
}
2 changes: 1 addition & 1 deletion packages/error-codes/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
}
},
"echo": {
"executor": "rslib:echo",
"executor": "../../tools/rslib-plugin:echo",
"options": {
"textToEcho": "Hello World"
}
Expand Down
5 changes: 0 additions & 5 deletions packages/runtime-core/global.d.ts

This file was deleted.

68 changes: 52 additions & 16 deletions packages/runtime-core/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@module-federation/runtime-core",
"version": "0.14.0",
"version": "0.16.0",
"type": "module",
"author": "zhouxiao <codingzx@gmail.com>",
"main": "./dist/index.cjs.cjs",
"module": "./dist/index.esm.js",
"types": "./dist/index.cjs.d.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand All @@ -19,40 +19,76 @@
"dist/",
"README.md"
],
"scripts": {
"build": "rslib build"
},
"exports": {
".": {
"import": {
"types": "./dist/index.esm.d.ts",
"default": "./dist/index.esm.js"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"require": {
"types": "./dist/index.cjs.d.ts",
"default": "./dist/index.cjs.cjs"
"types": "./dist/index.d.ts",
"default": "./dist/index.cjs"
}
},
"./types": {
"import": {
"types": "./dist/types.esm.d.ts",
"default": "./dist/types.esm.js"
"types": "./dist/types.d.ts",
"default": "./dist/types.js"
},
"require": {
"types": "./dist/types.cjs.d.ts",
"default": "./dist/types.cjs.cjs"
"types": "./dist/types.d.ts",
"default": "./dist/types.cjs"
}
},
"./helpers": {
"import": {
"types": "./dist/helpers.d.ts",
"default": "./dist/helpers.js"
},
"require": {
"types": "./dist/helpers.d.ts",
"default": "./dist/helpers.cjs"
}
},
"./core": {
"import": {
"types": "./dist/core.d.ts",
"default": "./dist/core.js"
},
"require": {
"types": "./dist/core.d.ts",
"default": "./dist/core.cjs"
}
},
"./global": {
"import": {
"types": "./dist/global.d.ts",
"default": "./dist/global.js"
},
"require": {
"types": "./dist/global.d.ts",
"default": "./dist/global.cjs"
}
}
},
"typesVersions": {
"*": {
".": [
"./dist/index.cjs.d.ts"
"./dist/index.d.ts"
],
"types": [
"./dist/types.cjs.d.ts"
"./dist/types.d.ts"
]
}
},
"dependencies": {
"@module-federation/sdk": "workspace:*",
"@module-federation/error-codes": "workspace:*"
"@module-federation/error-codes": "workspace:*",
"@module-federation/sdk": "workspace:*"
},
"devDependencies": {
"@rslib/core": "^0.10.4"
}
}
16 changes: 4 additions & 12 deletions packages/runtime-core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
"tags": ["type:pkg"],
"targets": {
"build": {
"executor": "@nx/rollup:rollup",
"executor": "../../tools/rslib-plugin:build",
"outputs": ["{workspaceRoot}/packages/runtime-core/dist"],
"options": {
"parallel": false,
"configFile": "rslib.config.ts",
"outputPath": "packages/runtime-core/dist",
"main": "packages/runtime-core/src/index.ts",
"additionalEntryPoints": ["packages/runtime-core/src/types.ts"],
"tsConfig": "packages/runtime-core/tsconfig.lib.json",
"assets": [],
"external": ["@module-federation/*"],
"project": "packages/runtime-core/package.json",
"compiler": "swc",
"rollupConfig": "packages/runtime-core/rollup.config.cjs",
"format": ["cjs", "esm"],
"generatePackageJson": false
"mode": "production",
"verbose": true
},
"dependsOn": [
{
Expand Down
44 changes: 44 additions & 0 deletions packages/runtime-core/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { defineConfig } from '@rslib/core';
import pkg from './package.json';
const FEDERATION_DEBUG = process.env.FEDERATION_DEBUG || '';

export default defineConfig({
source: {
entry: {
index: './src/index.ts',
types: './src/types.ts',
helpers: './src/helpers.ts',
core: './src/core.ts',
global: './src/global.ts',
},
define: {
__VERSION__: JSON.stringify(pkg.version),
FEDERATION_DEBUG: JSON.stringify(FEDERATION_DEBUG),
FEDERATION_ALLOW_NEW_FUNCTION: JSON.stringify(
process.env.FEDERATION_ALLOW_NEW_FUNCTION || false,
),
},
tsconfigPath: './tsconfig.lib.json',
},
output: {
target: 'node',
format: ['esm', 'cjs'],
distPath: {
root: './dist',
},
},
lib: [
{
format: 'esm',
dts: {
bundle: false,
distPath: './dist',
},
},
{
format: 'cjs',
},
],
bundle: false,
external: ['@module-federation/sdk', '@module-federation/error-codes'],
});
5 changes: 5 additions & 0 deletions packages/runtime-core/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="@rslib/core/types" />

declare const __VERSION__: string;
declare const FEDERATION_DEBUG: string;
declare const FEDERATION_ALLOW_NEW_FUNCTION: boolean | string;
13 changes: 13 additions & 0 deletions packages/runtime-core/src/global-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Federation } from './global';
import { RemoteEntryExports } from './type';

declare global {
// eslint-disable-next-line no-var
var __FEDERATION__: Federation,
__VMOK__: Federation,
// eslint-disable-next-line no-var
__GLOBAL_LOADING_REMOTE_ENTRY__: Record<
string,
undefined | Promise<RemoteEntryExports | void>
>;
}
Loading
Loading