@efox/emp-tune-dts-plugin
v1.3.5
Published
Tune d.ts Plugin
Downloads
1,992
Readme
@efox/emp-tune-dts-plugin
Generate type files for Module Federation project
English | 简体中文
🧐 Why
- In Typescript development, quoting remote project content requires type file support.
- The module type generated by tsc is a relative path and cannot be used by remote projects.
- Module Federation issues: How typesafe can a remote be with Typescript?
✨ Feature
- Generate a d.ts file containing all types of the project
- Type with current project name, not relative path
- Form a closed loop of types, from generation to reference complete
- Support custom modification
😊 Example
When there is no emp-tune-dts-plugin in this world
The type file generated by directly executing tsc -d
is a relative path.
After pulling this type of file to the sub-project, the sub-project cannot recognize the type of the remote component, resulting in failure to compile successfully and type prompts.
When this world has emp-tune-dts-plugin
After executing yarn emp build --ts
, a type file index.d.ts with the current project name as the path prefix will be generated.
Drag the type file generated by emp-tune-dts-plugin to the sub-project, the sub-project can not only recognize the type of the remote component, but also compile successfully and have type prompts. Reference to remote components, methods, etc. and hints, there is a feeling of service discovery on microservices.
👨🔧 Architecture
📦 Quick start
npm i @efox/emp-tune-dts-plugin
or yarn add @efox/emp-tune-dts-plugin
👨🏻💻 Use plugins on Webpack
const { TuneDtsPlugin } = require('@efox/emp-tune-dts-plugin')
Way 1 recommended
const createName = 'index.d.ts'
const createPath = './dist'
function operationDemo(fileData) {
console.log(fileData)
return fileData;
}
plugin.tunedts = {
plugin: TuneDtsPlugin,
args: [
{
output: path.join(createPath, createName),
path: createPath,
name: createName,
isDefault:true,
// Incoming function custom operation
operation: operationDemo
},
],
};
Way 2
function operationDemo(fileData) {
console.log(fileData)
return fileData;
}
plugins: [
new TuneDtsPlugin({
output: path.join(createPath, createName),
path: createPath,
name: createName,
isDefault:true,
// Incoming function custom operation
operation: operationDemo
})
]
Parameter explanation: | Parameter | Type | Explanation | | ---- | ---- | --- | | output| string (Required)| d.ts File output directory| | path| string (Required)| d.ts Folder path| | name| string (Required)| d.ts File name| | isDefault | boolean(Required) | Replace relative paths with absolute paths by default | | isRmExportDefault | boolean(Optional) | remove default = | | operation| Function (Optional)| Custom operation d.ts file function (when isDefault is true, operation will inherit the content after the default Replace). The input parameter is the content of the d.ts file, and the d.ts data must be returned after the operation is completed. operationDemo as an example|
💪 Generate
- After connecting to the Webpack Plugin, run Webpack to generate the type file of the current Module Federation project and save it in dist
🔗 Remote reference
Way 1
yarn add @efox/emp-cli
yarn emp tss YourRemoteProjectAddress /index.d.ts -n YourRemoteProjectName.d.ts
Way 2
Use VSCode plugin: emp-sync-base