@mcplex-js/webpack-plugin
v0.1.0
Published
Webpack plugin for MCPlex that compiles tools, generates TypeScript declarations, and creates WASM files
Maintainers
Readme
@mcplex-js/webpack-plugin
A Webpack plugin for MCPlex that automates the compilation of tools, generates TypeScript declarations, and creates WASM files.
Features
- AST-based Function Extraction: Uses TypeScript's compiler API to accurately parse and extract exported functions
- Tools Compilation: Compiles
tools.tsto cleantools.jsoutput using webpack - TypeScript Declarations: Generates
tools.d.tswith proper type definitions (I32return types, no parameters) - WASM Generation: Converts compiled tools to WASM using
extism-js - Asset Management: Copies
mcplex.jsonto the output directory - Dual Format Support: Available in both ESM and CommonJS formats
Installation
npm install @mcplex-js/webpack-pluginUsage
Basic Usage
const MCPlexWebpackPlugin = require('@mcplex-js/webpack-plugin');
module.exports = {
// ... your webpack config
plugins: [
new MCPlexWebpackPlugin({
inputFile: 'src/tools.ts',
moduleName: 'main',
})
]
};ES Modules
import MCPlexWebpackPlugin from '@mcplex-js/webpack-plugin';
export default {
// ... your webpack config
plugins: [
new MCPlexWebpackPlugin({
inputFile: 'src/tools.ts',
moduleName: 'main',
})
]
};Configuration Options
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| inputFile | string | 'src/tools.ts' | Path to the tools TypeScript file |
| moduleName | string | 'main' | Module name for the generated declarations |
| compileTools | boolean | true | Enable tools compilation |
| copyMcplexJson | boolean | true | Copy mcplex.json to output directory |
| generateWasm | boolean | true | Generate WASM file using extism-js |
| mcplexJsonPath | string | 'mcplex.json' | Path to mcplex.json file |
Example Configuration
const MCPlexWebpackPlugin = require('@mcplex-js/webpack-plugin');
module.exports = {
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
new MCPlexWebpackPlugin({
inputFile: 'src/tools.ts',
moduleName: 'main',
compileTools: true,
copyMcplexJson: true,
generateWasm: true,
mcplexJsonPath: 'mcplex.json',
})
]
};Output Files
The plugin generates the following files in your webpack output directory:
tools.js- Compiled tools (CommonJS format)tools.d.ts- TypeScript declarations withI32return typestools.wasm- WASM file generated from tools.jsmcplex.json- Copied configuration file
Requirements
- Node.js >= 16
- Webpack >= 5.0.0
extism-jsCLI tool (for WASM generation)
License
MIT
