docs/ecosystem/bundler-plugin.md
The @qiankunjs/bundler-plugin provides bundler plugins for the qiankun micro-frontend framework. Currently it supports Webpack (4 & 5), with plans to support other bundlers like Vite and Turbopack in the future.
npm install @qiankunjs/bundler-plugin --save-dev
# or
yarn add @qiankunjs/bundler-plugin --dev
# or
pnpm add @qiankunjs/bundler-plugin --save-dev
jsonpFunction/chunkLoadingGlobal names to prevent conflicts between micro applicationswindow for proper browser executionentry attribute to the main entry script tag in HTML using webpack entrypoints// webpack.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/bundler-plugin');
module.exports = {
entry: './src/index.js',
plugins: [
new QiankunWebpackPlugin()
]
};
This basic configuration will:
name field from your package.json as the library nameentry attribute (based on webpack entrypoints)// webpack.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/bundler-plugin');
module.exports = {
entry: './src/index.js',
plugins: [
new QiankunWebpackPlugin({
packageName: 'my-micro-app',
})
]
};
packageName (optional)stringpackage.json name field// craco.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/bundler-plugin');
module.exports = {
webpack: {
configure: (webpackConfig) => {
webpackConfig.plugins.push(
new QiankunWebpackPlugin({
packageName: process.env.REACT_APP_NAME || 'react-app'
})
);
return webpackConfig;
}
}
};
// vue.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/bundler-plugin');
module.exports = {
configureWebpack: {
plugins: [
new QiankunWebpackPlugin()
]
},
devServer: {
port: 8080,
headers: {
'Access-Control-Allow-Origin': '*'
}
}
};
// custom-webpack.config.js
const { QiankunWebpackPlugin } = require('@qiankunjs/bundler-plugin');
module.exports = {
plugins: [
new QiankunWebpackPlugin({
packageName: 'angular-micro-app'
})
]
};
Webpack 4:
{
output: {
library: 'your-app-name',
libraryTarget: 'window',
jsonpFunction: 'webpackJsonp_your-app-name',
globalObject: 'window'
}
}
Webpack 5:
{
output: {
library: {
name: 'your-app-name',
type: 'window'
}
}
}
The plugin uses webpack entrypoints to identify the main entry chunk and marks its script tag with entry. If multiple entrypoints exist, it matches by HTML filename; otherwise it falls back to the first entrypoint. If detection fails, it marks the last injected script.
package.json has a valid name field, or explicitly set packageName in plugin options.html-webpack-plugin is present and the plugin is listed after it in plugins. The plugin relies on webpack compilation.entrypoints to find the main chunk.Found an issue or want to contribute? Check out the GitHub repository and contribute to the packages/bundler-plugin directory.